Issue Details (XML | Word | Printable)

Key: OSGI-611
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Costin Leau
Reporter: Michael Pilquist
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring OSGi

Intermittent deadlock between OsgiServiceFactoryBean and OsgiServiceProxyFactoryBean.stateListeners during shutdown of integration tests

Created: 22/Aug/08 03:46 PM   Updated: 06/Sep/08 01:06 PM
Component/s: CORE
Affects Version/s: 1.1.1
Fix Version/s: 1.2 M1, 1.1.2

Time Tracking:
Not Specified


 Description  « Hide
I've been running in to an intermittent deadlock on shutdown of a Spring-DM powered integration test. About once every five runs, when the integration test finishes, I get the following output from Spring-DM:

ERROR [er.internal.util.concurrent.RunnableTimedExecution] - Closing runnable for context OsgiBundleXmlApplicationContext(bundle=****, config=osgibundle:/META-INF/spring/*.xml) did not finish in 10000ms; consider taking a snapshot and then shutdown the VM in case the thread still hangs

After getting this, the VM hangs until I force quit it. This is problematic when the tests are run as part of continuous integration because the build is always hung.

Below is a capture of the stack trace when the VM is hung. You can see there's a deadlock between Timer-1 and Thread-8 threads. Timer-1 thread first acquired the lock on OsgiServiceFactoryBean (id=3211) and is then trying to acquire the lock on the list of stateListeners (id=3266). Thread-8 acquires the lock on the stateListeners list first. This could be fixed by always acquiring the OsgiServiceFactoryBean lock before the stateListeners lock.


Java HotSpot(TM) 64-Bit Server VM[localhost:10000] (Suspended)
Thread Group [system]
Daemon System Thread [Reference Handler] (Suspended)
Daemon System Thread [Finalizer] (Suspended)
Daemon System Thread [Signal Dispatcher] (Suspended)
Thread Group [main]
Thread [main] (Suspended)
Daemon Thread [Framework Event Dispatcher] (Suspended)
Daemon Thread [Start Level Event Dispatcher] (Suspended)
Thread [Configuration Updater] (Suspended)
Daemon Thread [Timer-1] (Suspended)
owns: OsgiServiceFactoryBean (id=3211)
owns: LinkedHashMap<K,V> (id=3453)
owns: Object (id=3454)
owns: Object (id=3455)
waiting for: Collections$SynchronizedRandomAccessList<E> (id=3266)
Collections$SynchronizedRandomAccessList<E>(Collections$SynchronizedCollection<E>).remove(Object) line: 1580
OsgiServiceProxyFactoryBean$Executor.removeStateListener(ImporterStateListener) line: 78
ImporterController.removeStateListener(ImporterStateListener) line: 41
DefaultMandatoryDependencyManager.removeListener(Object, ImporterStateListener) line: 301
DefaultMandatoryDependencyManager.removeServiceExporter(Object, String) line: 268
MandatoryDependencyBeanPostProcessor.postProcessBeforeDestruction(Object, String) line: 77
DisposableBeanAdapter.destroy() line: 140
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroyBean(String, DisposableBean) line: 456
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroySingleton(String) line: 434
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroySingletons() line: 407
OsgiBundleXmlApplicationContext(AbstractApplicationContext).destroyBeans() line: 854
OsgiBundleXmlApplicationContext(AbstractOsgiBundleApplicationContext).destroyBeans() line: 211
OsgiBundleXmlApplicationContext(AbstractApplicationContext).doClose() line: 832
OsgiBundleXmlApplicationContext(AbstractOsgiBundleApplicationContext).doClose() line: 204
OsgiBundleXmlApplicationContext(AbstractDelegatedExecutionApplicationContext).normalClose() line: 169
DependencyWaiterApplicationContextExecutor.close() line: 354
OsgiBundleXmlApplicationContext(AbstractDelegatedExecutionApplicationContext).doClose() line: 181
OsgiBundleXmlApplicationContext(AbstractApplicationContext).close() line: 795
ContextLoaderListener$1.run() line: 539
RunnableTimedExecution$MonitoredRunnable.run() line: 60
DelegatingTimerTask.run() line: 66
TimerThread.mainLoop() line: 512 [local variables unavailable]
TimerThread.run() line: 462
Thread [Thread-8] (Suspended)
owns: Collections$SynchronizedRandomAccessList<E> (id=3266)
owns: LinkedHashMap<K,V> (id=3456)
waiting for: OsgiServiceFactoryBean (id=3211)
DefaultMandatoryDependencyManager$ImporterDependencyListener.importerUnsatisfied(Object, OsgiServiceDependency) line: 102
ServiceDynamicInterceptor$Listener.notifyUnsatisfiedStateListeners() line: 268
ServiceDynamicInterceptor$Listener.serviceChanged(ServiceEvent) line: 236
FilteredServiceListener.serviceChanged(ServiceEvent) line: 94
BundleContextImpl.dispatchEvent(Object, Object, int, Object) line: 1224
EventManager.dispatchEvent(EventListeners$ListElement[], EventDispatcher, int, Object) line: 195
ListenerQueue.dispatchEventSynchronous(int, Object) line: 141
Framework.publishServiceEventPrivileged(ServiceEvent) line: 1603
Framework.publishServiceEvent(int, ServiceReference) line: 1578
ServiceRegistrationImpl.unregister() line: 156
ServiceRegistrationDecorator.unregister() line: 63
OsgiServiceUtils.unregisterService(ServiceRegistration) line: 41
OsgiServiceFactoryBean.unregisterService(ServiceRegistration) line: 464
OsgiServiceFactoryBean.unregisterService() line: 454
OsgiServiceFactoryBean(AbstractOsgiServiceExporter).destroy() line: 83
DisposableBeanAdapter.destroy() line: 151
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroyBean(String, DisposableBean) line: 456
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroySingleton(String) line: 434
DefaultListableBeanFactory(DefaultSingletonBeanRegistry).destroySingletons() line: 407
OsgiBundleXmlApplicationContext(AbstractApplicationContext).destroyBeans() line: 854
OsgiBundleXmlApplicationContext(AbstractOsgiBundleApplicationContext).destroyBeans() line: 211
OsgiBundleXmlApplicationContext(AbstractApplicationContext).doClose() line: 832
OsgiBundleXmlApplicationContext(AbstractOsgiBundleApplicationContext).doClose() line: 204
OsgiBundleXmlApplicationContext(AbstractDelegatedExecutionApplicationContext).normalClose() line: 169
AbstractDelegatedExecutionApplicationContext$NoDependenciesWaitRefreshExecutor.close() line: 77
OsgiBundleXmlApplicationContext(AbstractDelegatedExecutionApplicationContext).doClose() line: 181
AbstractApplicationContext$1.run() line: 765
Thread [Thread-0] (Suspended)
Thread Group [spring-osgi-extender[2b80e8d1]-threads]
Daemon Thread [Timer-2] (Suspended)
Thread [pool-1-thread-1] (Suspended)

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Costin Leau added a comment - 27/Aug/08 09:09 AM
Michael, I've added a fix in the 1.1.x branch. The nightly build has ran so it should be available in the snapshot maven repo. Try it out and let me know if it works for you.
Thanks,

Michael Pilquist added a comment - 29/Aug/08 08:52 AM
Hi Costin,

I've tested with the latest SNAPSHOTs as of this morning and I haven't been able to reproduce the problem. Thanks for the help!

Michael