FELIX-881 Also clear the configurationAdminRegistration field before
actually unregistering the service prevents IllegalStateException
in getServiceReference() in extreme multi-threaded cases
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@734635 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
index 35bbdfc..af74954 100644
--- a/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
+++ b/configadmin/src/main/java/org/apache/felix/cm/impl/ConfigurationManager.java
@@ -191,8 +191,14 @@
{
// immediately unregister the Configuration Admin before cleaning up
- configurationAdminRegistration.unregister();
- configurationAdminRegistration = null;
+ // clearing the field before actually unregistering the service
+ // prevents IllegalStateException in getServiceReference() if
+ // the field is not null but the service already unregistered
+ if (configurationAdminRegistration != null) {
+ ServiceRegistration reg = configurationAdminRegistration;
+ configurationAdminRegistration = null;
+ reg.unregister();
+ }
// stop handling ManagedService[Factory] services
managedServiceFactoryTracker.close();