Xander Uiterlinden created FELIX-4597:
-----------------------------------------
Summary: Race issue causing ConcurrentModificationException in
org.apache.felix.http.whiteboard.internal.manager.ExtenderManager.add(ExtenderManager.java:111)
Key: FELIX-4597
URL: https://issues.apache.org/jira/browse/FELIX-4597
Project: Felix
Issue Type: Bug
Components: HTTP Service
Affects Versions: http-2.3.0
Reporter: Xander Uiterlinden
Quite frequently when launching our application we're getting a
ConcurrentModificationException, see the following stacktrace:
java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429)
at java.util.HashMap$KeyIterator.next(HashMap.java:1453)
at
org.apache.felix.http.whiteboard.internal.manager.ExtenderManager.add(ExtenderManager.java:111)
at
org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker.added(HttpContextTracker.java:37)
at
org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker.added(HttpContextTracker.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:932)
at
org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864)
at
org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at
org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:8
This is caused by a race issue where one thread is adding HttpContext where
another thread is adding a servlet for this context at the same time.
Thread A:
In ExtenderManager.addHttpContext(service, ref) the http context is added to
the context manager which returns a collection of mappings. This collection is
the actual collection as administered by the HttpContextHolder.
In a for loop* on these mappings the mappings are registered with the
HttpService.
Collection<AbstractMapping> mappings =
this.contextManager.addHttpContext(bundle, contextId, service);
Thread B:
When adding a servlet on the other thread, getHttpContext(mapping, ref) is
called which calls getHttpContext(bundle, contextId, mapping). Here the
HttpContextHolder is obtained by HttpContextHolder holder = this.idMap.get(id).
After which holder.addMapping(mapping) is called. This addMapping is called
while thread A is still in it's for loop iterating over the mappings.
This requires synchronization. It would actually be nice to be able to
synchronize on a particular HttpContext. This would require some method
refactoring.
--
This message was sent by Atlassian JIRA
(v6.2#6252)