You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Ronald Chen (JIRA)" <ji...@apache.org> on 2013/01/15 23:12:12 UTC

[jira] [Comment Edited] (FELIX-3846) Felix + Felix HTTP Jetty causes IllegalStateException during start up

    [ https://issues.apache.org/jira/browse/FELIX-3846?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13554185#comment-13554185 ] 

Ronald Chen edited comment on FELIX-3846 at 1/15/13 10:10 PM:
--------------------------------------------------------------

Here is a patch with one way of fixing this issue.

I replaced the wait/interrupt calls with a CyclicBarrier of size 2.

After applying this patch I could not reproduce the problem.

What wait/interrupt is really doing is sending a signal to the jetty thread to resume it so it can restarted.

Therefore I created methods that reflect this understanding.  The usage of the restart barrier can actually be extracted into its own class.

                
      was (Author: pyrolistical):
    Here is a patch with one way of fixing this issue.

I replaced the wait/interrupt calls with a CyclicBarrier of size 2.

After applying this patch I could not reproduce the problem.
                  
> Felix + Felix HTTP Jetty causes IllegalStateException during start up
> ---------------------------------------------------------------------
>
>                 Key: FELIX-3846
>                 URL: https://issues.apache.org/jira/browse/FELIX-3846
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework, HTTP Service
>    Affects Versions: framework-4.0.3, http-2.2.0
>         Environment: Java version: 1.6.0_37, vendor: Apple Inc.
> All operating systems
>            Reporter: Ronald Chen
>         Attachments: felix-http-jetty-2.2.0-fix-illegal-state-exception.patch
>
>
> There is a race condition during the activation of the felix http jetty bundle when used within a felix container.
> During the activation of the felix http jetty bundle you will intermittently see:
> java.lang.IllegalStateException: Can only register services while bundle is active or activating.
> 	at org.apache.felix.framework.Felix.registerService(Felix.java:3209) ~[na:na]
> 	at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346) ~[na:na]
> 	at org.apache.felix.http.base.internal.HttpServiceController.register(HttpServiceController.java:135) ~[org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.apache.felix.http.base.internal.DispatcherServlet.init(DispatcherServlet.java:48) ~[org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.jetty.Server.doStart(Server.java:224) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.apache.felix.http.jetty.internal.JettyService.initializeJetty(JettyService.java:164) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.apache.felix.http.jetty.internal.JettyService.startJetty(JettyService.java:115) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at org.apache.felix.http.jetty.internal.JettyService.run(JettyService.java:290) [org.apache.felix.http.jetty_2.2.0.jar:na]
> 	at java.lang.Thread.run(Thread.java:680) [na:1.6.0_37]
> I debugged into line Felix.java:3209 and discovered the cause by is thrown by Felix.java:4875 which is:
> throw new IllegalStateException("Unable to acquire bundle lock, thread interrupted.");
> I dug around and discovered the thread which acquired the lock was the one created on JettyService.java:75
> Looking at usages of the thread field, I think I discovered the source of the interrupt on line JettyService.java:75.
> What I think is happening is this:
> 1. felix container starts jetty bundle
> 2. jetty activator is run which creates a new jetty service
> 3. jetty service creates a new thread and initializes jetty
> 4. jetty attempts to register the http service to the felix container and obtains the felix bundle lock (Felix.java:4871)
> 5. at the same time something calls JettyService.update(Dictionary) which interrupts the thread in attempts to restart the jetty server
> 6. this causes the felix bundle lock to be interrupted and IllegalStateException is thrown
> At which point the http service is not registered and we sob quietly.
> To fix this issue I think the thread jetty service creates should never leave the jetty space.  When it needs to register the http service a new thread should be created so it doesn't allow the possibility of the jetty service thread to obtain a lock it shouldn't.
> Alternatively in stop using interrupt() to signal change as it is dangerous!  Use a java 5 concurrent lock object.
> Repo case:
> I can repo this case within my own system by restarting bundle "Apache Felix Http Jetty (2.2.0)" again and again, but I don't know if there is a smaller repo case.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira