Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-6386

Race condition in initialization of Activators (Port already in use: 1099)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 4.3.0, 4.2.7
    • karaf
    • None

    Description

      Recently I came across the problem mentioned in KARAF-5054 (at startup - Port already in use: 1099 - whereas another port is specified in configuration)

      After digging through debugger - I see this is indeed a "race condition" issue - Activator's doStart() in one thread happens before "CM Configuration Updater" thread reaches to the same activator and provides appropriate properties. And it may affect other activators.

      The bug as i see it - SomeActivator.doStart() do not ensure startup configuration is loaded before start, however all need environment is already available. I've fixed this for myself in the following way. Please apply to sources if it seems appropriate:

      1. Add this method into org/apache/karaf/util/tracker/BaseActivator.java

          protected boolean ensureStartupConfiguration(String configId) throws IOException {
              if (this.configuration != null) {
                  return true;
              }
      
              ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
              if (configurationAdmin != null) {
                  Configuration configuration = configurationAdmin.getConfiguration(configId);
                  Dictionary<String, Object> properties = (configuration == null) ? null : configuration.getProperties();
      
                  if (properties != null) {
                      this.configuration = properties;
                      return true;
                  }
              }
      
              // Since logging may not get initialized - let's spam directly to console
              System.out.println("No startup configuration for: " + configId);
      
              return false;
          }
      

      2. Add following initialization line ... 

          protected void doStart() throws Exception {
              // Verify dependencies
              ConfigurationAdmin configurationAdmin = ...
      
              if (!ensureStartupConfiguration("org.apache.karaf.management")) {
                  return;
              }
      

      ... into affected activators. Here is the list I've got in my environment:

      org.apache.karaf.jaas.modules.impl.Activator - CM Configuration Updater (ManagedService Update: pid=[org.apache.karaf.jaas]):
        file:/.../etc/org.apache.karaf.jaas.cfg
      org.apache.karaf.kar.internal.osgi.Activator - CM Configuration Updater (ManagedService Update: pid=[org.apache.karaf.kar]):
        file:/.../etc/org.apache.karaf.kar.cfg
      org.apache.karaf.log.core.internal.osgi.Activator - CM Configuration Updater (ManagedService Update: pid=[org.apache.karaf.log]):
        file:/.../etc/org.apache.karaf.log.cfg
      org.apache.karaf.management.internal.Activator - CM Configuration Updater (ManagedService Update: pid=[org.apache.karaf.management]):
        file:/.../etc/org.apache.karaf.management.cfg
      org.apache.karaf.shell.ssh.Activator - CM Configuration Updater (ManagedService Update: pid=[org.apache.karaf.shell]):
        file:/.../etc/org.apache.karaf.shell.cfg
      

      Attachments

        Issue Links

          Activity

            People

              jbonofre Jean-Baptiste Onofré
              xtracoder Xtra Coder
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: