FELIX-6331: fix a race condtion in unget service from service factory.
diff --git a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
index 68bab2c..34d49d5 100644
--- a/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
+++ b/framework/src/main/java/org/apache/felix/framework/ServiceRegistry.java
@@ -502,11 +502,11 @@
if (svc != null)
{
- // Check the count again to ensure that nobody else has just
- // obtained the service again
- if (usage.m_count.get() <= 0)
+ if (usage.m_svcHolderRef.compareAndSet(holder, null))
{
- if (usage.m_svcHolderRef.compareAndSet(holder, null))
+ // Check the count again to ensure that nobody else has just
+ // obtained the service again
+ if (usage.m_count.get() <= 0)
{
// Temporarily increase the usage again so that the
// service factory still sees the usage in the unget
@@ -521,7 +521,6 @@
// now we can decrease the usage again
usage.m_count.decrementAndGet();
}
-
}
}
}