Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-3456

Component ignores required static service addition when in Activating state

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • scr-1.6.0
    • scr-1.6.2
    • None
    • Using org.apache.felix.scr svn rev 1298268 on Mac

    Description

      I have a component with two required static service references (A and B). In my scenario A and B are registered nearly simultaneously on different threads and this causes the DependencyManager to ignore the addition of one of these two services (B). This causes the component to remain unsatisfied and never activate, since the service that was ignored is not re-registered at any time and nothing subsequently causes the component to re-activate.

      This happens as follows:
      12:30:59:317 Thread 1 - Registers Service B/257
      12:30:59:320 Thread 2 - Registers Service A/258
      12:30:59:320 Thread 2 - Dependency Manager: Adding Service A/258
      12:30:59:321 Thread 2 - Dependency Manager: Service serviceA registered, activate component
      12:30:59:321 Thread 2 - State transition : Unsatisfied -> Activating
      12:30:59:321 Thread 2 - Activating component
      12:30:59:321 Thread 1 - Dependency Manager: Adding Service B/257
      12:30:59:321 Thread 2 - Dependency not satisfied: serviceB
      12:30:59:321 Thread 1 - Dependency Manager: Added service serviceB is ignored for static reference <--- I believe we end up here because Thread 2 has moved the component from Unsatisfied to Activating and the reference is a static reference
      12:30:59:321 Thread 2 - Not all dependencies satisified, cannot activate
      12:30:59:321 Thread 2 - State transition : Activating -> Unsatisfied

      Because the addition of Service B has been ignored and serviceB is a required dependency my component then never activates even though my reqiured service is present.

      There is a comment in DependencyManager#serviceAdded method:
      // FELIX-1413: if the dependency is static and the component is
      // satisfied (active) added services are not considered until
      // the component is reactivated for other reasons.

      This suggests that the static service should only be ignored if the component is satisfied(active), which would be correct, but in this case the component is only activating (and will fail to activate because one of the two dependencies is not yet satisfied) and there is no check of state at this time.
      A simple fix would be to check the state of the component as well as if the service is static e.g.
      replace if ( m_dependencyMetadata.isStatic() )
      with if ( m_dependencyMetadata.isStatic() && m_componentManager.getState() == AbstractComponentManager.STATE_ACTIVE )

      This is an easy fix, but I guess may leave a small window where a static reference could get replaced while a component was still activating if another instance of the same service was registered on a different thread.
      There are other fixes that could be done by synchronizing more around service additions.

      Is anyone willing to make this fix or does anyone have any thoughts about this issue?
      Thanks

      Attachments

        1. FELIX-3456-8a.diff
          56 kB
          David Jencks
        2. FELIX-3456-8.diff
          57 kB
          David Jencks
        3. FELIX-3456-7a.diff
          12 kB
          David Jencks
        4. FELIX-3456-7.diff
          68 kB
          David Jencks
        5. FELIX-3456-fmeschbe-6.patch
          57 kB
          Felix Meschberger
        6. FELIX-3456-5b.diff
          34 kB
          David Jencks
        7. FELIX-3456-5a.diff
          25 kB
          David Jencks
        8. FELIX-3456-5.diff
          54 kB
          David Jencks
        9. FELIX-3456-fmeschbe.patch
          9 kB
          Felix Meschberger
        10. FELIX-3456-1.1.diff
          1 kB
          Michael Fraenkel
        11. FELIX-3456-4.diff
          28 kB
          David Jencks
        12. FELIX-3456-3.diff
          24 kB
          David Jencks
        13. FELIX-3456-1.diff
          16 kB
          David Jencks

        Activity

          People

            djencks David Jencks
            ricellis Richard Ellis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: