Felix
  1. Felix
  2. FELIX-3713

Bundle.start() returns without starting the bundle

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: framework-4.0.2
    • Fix Version/s: framework-4.2.0
    • Component/s: Framework
    • Labels:
      None

      Description

      See email exchange between Sahoo & Richard that happened in dev alias on 16th Oct 2012 for issue details:

      > While investigating some issues in GlassFish, what we are seeing is that even if our code is calling bundle.start(START_TRANSIENT), the bundle is not getting started immediately, nor is the code blocking. It simply returns without Bundle's activator getting called and bundle.getState() == RESOLVED. We see this happening when there is a start level change in progress. We are currently using Felix 4.0.2. Looking at the code, I see this to be by design, but isn't it a non-compliant behavior? Should bundle.start() not wait until the bundle is started?

      The spec has always been a little lenient about how start levels are processed to give leeway to the frameworks. For us, we viewed this as somewhat of a race condition between threads starting bundles and the start level thread.

      However, in the transient case, I wouldn't expect it to remain in RESOLVED state. If its start level wasn't met, it should have thrown an exception. Yet there is a chance in the transient case that it could start asynchronously...not sure if this would really be problematic for you or not...

      But it shouldn't remain in the RESOLVED state. Looking at the code, I think there is a bug in this scenario where a transient bundle that is handled asynchronously will not actually end up getting started since the start level thread checks the persistent state of the bundle, which is not set for transient bundles.

      You could definitely open up a bug for this last issue...

      -> richard

        Activity

        Sahoo created issue -
        Richard S. Hall made changes -
        Field Original Value New Value
        Fix Version/s framework-4.2.0 [ 12317972 ]
        Hide
        TangYong added a comment -

        I think that the problem needs to be fixed in felix, I offer a real use case as following:

        On glassfish starting, there is a Start Level thread to adjust Start Level, in the process of executing the Start Level thread, I have a bundle tracker to trace some bundle to start the bundle in order to finish something. I used bundle.start(Bundle.START_TRANSIENT) to start the bundle while tracing the bundle. However, the bundle's activator was not executed. If I used bundle.start() method to start the bundle while tracing the bundle, although the bundle's activator was executed, the bundle's ondemand starting(on some cases, the bundle maybe started by other handling logic) disappeared because bundle.start() method keeped bundle's state persisted.

        So, I wish that felix team can fix it.

        Thanks.
        --Tang

        Show
        TangYong added a comment - I think that the problem needs to be fixed in felix, I offer a real use case as following: On glassfish starting, there is a Start Level thread to adjust Start Level, in the process of executing the Start Level thread, I have a bundle tracker to trace some bundle to start the bundle in order to finish something. I used bundle.start(Bundle.START_TRANSIENT) to start the bundle while tracing the bundle. However, the bundle's activator was not executed. If I used bundle.start() method to start the bundle while tracing the bundle, although the bundle's activator was executed, the bundle's ondemand starting(on some cases, the bundle maybe started by other handling logic) disappeared because bundle.start() method keeped bundle's state persisted. So, I wish that felix team can fix it. Thanks. --Tang
        Hide
        Richard S. Hall added a comment -

        Yep, that's why we opened an issue on it. Thanks.

        Show
        Richard S. Hall added a comment - Yep, that's why we opened an issue on it. Thanks.
        Hide
        Richard S. Hall added a comment -

        I'm not sure I see a great solution for this one. One possibility is to somehow pass along the fact in the tuple that this bundle is being transiently started as opposes to being a bundle that is persistently stopped. This still treats the bundle asynchronously and potentially is somewhat complicated since we'd somehow need to mark the bundle as STARTING so that it couldn't be stopped before it was started.

        Another approach is to treat transient bundles differently and directly activate them if their start level is met (or fail if it is not). The downside of this approach is that they may activate slightly out of order since it could not be coordinated with the start level thread's active start level.

        I think the latter approach is probably the better of the two.

        Show
        Richard S. Hall added a comment - I'm not sure I see a great solution for this one. One possibility is to somehow pass along the fact in the tuple that this bundle is being transiently started as opposes to being a bundle that is persistently stopped. This still treats the bundle asynchronously and potentially is somewhat complicated since we'd somehow need to mark the bundle as STARTING so that it couldn't be stopped before it was started. Another approach is to treat transient bundles differently and directly activate them if their start level is met (or fail if it is not). The downside of this approach is that they may activate slightly out of order since it could not be coordinated with the start level thread's active start level. I think the latter approach is probably the better of the two.
        Hide
        TangYong added a comment -

        Thanks richard's suggestions very much.
        I have a solution for this problem:

        The problem happened on the following codes(felix.java Line : 1820, and I used felix 4.0.2):

        if (!Thread.currentThread().getName().equals(FrameworkStartLevelImpl.THREAD_NAME))
        {
        synchronized (m_startLevelBundles)
        {
        if (!m_startLevelBundles.isEmpty())
        {
        // Only add the bundle to the start level bundles
        // being process if it is not already there.
        boolean found = false;
        for (StartLevelTuple tuple : m_startLevelBundles)
        {
        if (tuple.m_bundle == bundle)

        { found = true; }

        }
        if (!found)

        { ... m_startLevelBundles.add(new StartLevelTuple(bundle, bundleLevel)); }

        return;
        }
        }

        My solution is that :

        1) in Felix class, adding a public method to observer whether m_startLevelBundles is empty or not until FelixStartLevel thread finished.
        2) adding an api into StartLevel Service to make user or client see whether current bundle(tuple) is in m_startLevelBundles by 1)

        In this way, once finding current bundle is in m_startLevelBundles, client will wait until FelixStartLevel thread finished and then execute start(int) method.

        Do you agree with me?

        Thanks
        --Tang

        Show
        TangYong added a comment - Thanks richard's suggestions very much. I have a solution for this problem: The problem happened on the following codes(felix.java Line : 1820, and I used felix 4.0.2): if (!Thread.currentThread().getName().equals(FrameworkStartLevelImpl.THREAD_NAME)) { synchronized (m_startLevelBundles) { if (!m_startLevelBundles.isEmpty()) { // Only add the bundle to the start level bundles // being process if it is not already there. boolean found = false; for (StartLevelTuple tuple : m_startLevelBundles) { if (tuple.m_bundle == bundle) { found = true; } } if (!found) { ... m_startLevelBundles.add(new StartLevelTuple(bundle, bundleLevel)); } return; } } My solution is that : 1) in Felix class, adding a public method to observer whether m_startLevelBundles is empty or not until FelixStartLevel thread finished. 2) adding an api into StartLevel Service to make user or client see whether current bundle(tuple) is in m_startLevelBundles by 1) In this way, once finding current bundle is in m_startLevelBundles, client will wait until FelixStartLevel thread finished and then execute start(int) method. Do you agree with me? Thanks --Tang
        Hide
        TangYong added a comment -

        >2) adding an api into StartLevel Service to make user or client see whether current bundle(tuple) is in m_startLevelBundles by 1)
        I know that adding api for StartLevel will change OSGi Core Specification, maybe you do not agree with me, however, from a user's perspective, this should be a good way to resolve such a problem, after all, in current OSGi Core Specification, when appearing such a scene, there is not a clear description.

        Show
        TangYong added a comment - >2) adding an api into StartLevel Service to make user or client see whether current bundle(tuple) is in m_startLevelBundles by 1) I know that adding api for StartLevel will change OSGi Core Specification, maybe you do not agree with me, however, from a user's perspective, this should be a good way to resolve such a problem, after all, in current OSGi Core Specification, when appearing such a scene, there is not a clear description.
        Hide
        TangYong added a comment -

        Hi sahoo, richard,

        About the issue happened on glassfish, according to richard's reply, while attempting to execute "bundle.start(Bundle.START_TRANSIENT)" and the bundle is used by FelixStartLevel thread, using the following method should resolve the issue,

        1) before executing "bundle.start(Bundle.START_TRANSIENT), using StartLevel.getStartLevel() to seeing whether active start level value of the Framework is equal to the value of "glassfish.osgi.start.level.final".
        2) if being equal, this means that basiclly Framework Acitve StartLevel has been adjusted, and m_startLevelBundles has removed the transient bundle, then, we start to execute "bundle.start(Bundle.START_TRANSIENT).
        3) if not being equal, we do a loop until active start level value of the Framework is equal to the value of "glassfish.osgi.start.level.final", then, we start to execute "bundle.start(Bundle.START_TRANSIENT).

        I will spend some time to validate the above.

        Thanks
        --Tang

        Show
        TangYong added a comment - Hi sahoo, richard, About the issue happened on glassfish, according to richard's reply, while attempting to execute "bundle.start(Bundle.START_TRANSIENT)" and the bundle is used by FelixStartLevel thread, using the following method should resolve the issue, 1) before executing "bundle.start(Bundle.START_TRANSIENT), using StartLevel.getStartLevel() to seeing whether active start level value of the Framework is equal to the value of "glassfish.osgi.start.level.final". 2) if being equal, this means that basiclly Framework Acitve StartLevel has been adjusted, and m_startLevelBundles has removed the transient bundle, then, we start to execute "bundle.start(Bundle.START_TRANSIENT). 3) if not being equal, we do a loop until active start level value of the Framework is equal to the value of "glassfish.osgi.start.level.final", then, we start to execute "bundle.start(Bundle.START_TRANSIENT). I will spend some time to validate the above. Thanks --Tang
        Hide
        Richard S. Hall added a comment -

        I just committed a patch that modifies start level handling such that we always process transiently started bundles synchronously, which means they'll either be started on the calling thread if they meet the active start level or they will throw an exception if they don't. Please close if satisfied. Thanks.

        Show
        Richard S. Hall added a comment - I just committed a patch that modifies start level handling such that we always process transiently started bundles synchronously, which means they'll either be started on the calling thread if they meet the active start level or they will throw an exception if they don't. Please close if satisfied. Thanks.
        Richard S. Hall made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Richard S. Hall [ rickhall ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Richard S. Hall
            Reporter:
            Sahoo
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development