You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Marcel Offermans (JIRA)" <ji...@apache.org> on 2011/03/17 00:18:33 UTC

[jira] Commented: (FELIX-2881) ConcurrentModificationException in HTTP whiteboard bundle

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

Marcel Offermans commented on FELIX-2881:
-----------------------------------------

Upon analysis of this issue, it seems the following scenario unfolds:

1) The HttpService goes live, as can be seen from the stack trace, and triggers a call to ExtenderManagerImpl.registerAll().
2) ExtenderManagerImpl.registerAll() loops over its internal collection (which seems well guarded by the synchronized keywords on all methods that manipulate or go over the internal HashMap).
3) At some point in time, actually before the exception occurs, some servlet is registered with the HttpService that in turn creates a new Servlet that is added to the service registry.
4) The addition of a new Servlet triggers a call to ExtenderManagerImpl.addMapping() on the same thread, so it already has the lock and modfies the internal collection.
5) A little while later, the iterator tries to proceed with the next element and fails with the exception printed above.

The underlying problem is that at point 3) we invoke another service while holding a lock. That is never a good idea. It's better to, for example, create a copy of the list whilst holding the lock and then iterating over that copy outside of the lock.

> ConcurrentModificationException in HTTP whiteboard bundle
> ---------------------------------------------------------
>
>                 Key: FELIX-2881
>                 URL: https://issues.apache.org/jira/browse/FELIX-2881
>             Project: Felix
>          Issue Type: Bug
>          Components: HTTP Service
>    Affects Versions: http-2.2.0
>            Reporter: Marcel Offermans
>            Assignee: Marcel Offermans
>
> When starting up an OSGi application which uses the HTTP Jetty and whiteboard bundles, I get a concurrent modification exception a lot of the time:
> ERROR: EventDispatcher: Error during dispatch. (java.util.ConcurrentModificationException)
> java.util.ConcurrentModificationException
> 	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
> 	at java.util.HashMap$ValueIterator.next(HashMap.java:822)
> 	at org.apache.felix.http.whiteboard.internal.manager.ExtenderManagerImpl.registerAll(ExtenderManagerImpl.java:175)
> 	at org.apache.felix.http.whiteboard.internal.manager.ExtenderManagerImpl.setHttpService(ExtenderManagerImpl.java:154)
> 	at org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker.added(HttpServiceTracker.java:37)
> 	at org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker.added(HttpServiceTracker.java:24)
> 	at org.apache.felix.http.whiteboard.internal.tracker.AbstractTracker.addingService(AbstractTracker.java:36)
> 	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:896)
> 	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
> 	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
> 	at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:840)
> 	at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:871)
> 	at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:733)
> 	at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:662)
> 	at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:3733)
> 	at org.apache.felix.framework.Felix.access$000(Felix.java:80)
> 	at org.apache.felix.framework.Felix$2.serviceChanged(Felix.java:717)
> 	at org.apache.felix.framework.ServiceRegistry.registerService(ServiceRegistry.java:107)
> 	at org.apache.felix.framework.Felix.registerService(Felix.java:2854)
> 	at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:251)
> 	at org.apache.felix.http.base.internal.HttpServiceController.register(HttpServiceController.java:64)
> 	at org.apache.felix.http.base.internal.DispatcherServlet.init(DispatcherServlet.java:41)
> 	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
> 	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
> 	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
> 	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
> 	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
> 	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
> 	at org.mortbay.jetty.Server.doStart(Server.java:224)
> 	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
> 	at org.apache.felix.http.jetty.internal.JettyService.initializeJetty(JettyService.java:145)
> 	at org.apache.felix.http.jetty.internal.JettyService.startJetty(JettyService.java:112)
> 	at org.apache.felix.http.jetty.internal.JettyService.run(JettyService.java:203)
> 	at java.lang.Thread.run(Thread.java:680)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira