Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (revision 1652009) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreService.java (working copy) @@ -125,7 +125,7 @@ private SegmentStore store; - private SegmentNodeStore delegate; + private volatile SegmentNodeStore delegate; private ObserverTracker observerTracker; @@ -145,7 +145,7 @@ private boolean customBlobStore; @Override - protected synchronized SegmentNodeStore getNodeStore() { + protected SegmentNodeStore getNodeStore() { checkState(delegate != null, "service must be activated when used"); return delegate; } @@ -299,14 +299,8 @@ } @Deactivate - public synchronized void deactivate() { + public void deactivate() { unregisterNodeStore(); - - observerTracker.stop(); - delegate = null; - - store.close(); - store = null; } protected void bindBlobStore(BlobStore blobStore) throws IOException { @@ -320,11 +314,17 @@ } private void unregisterNodeStore() { - if(providerRegistration != null){ + observerTracker.stop(); + delegate = null; + + if (providerRegistration != null) { providerRegistration.unregister(); providerRegistration = null; } - if(storeRegistration != null){ + if (storeRegistration != null) { + // this call can trigger a deadlock with the #getNodeStore() method + // being called from other OSGi services whenever there's a change + // in the NodeStore service registration storeRegistration.unregister(); storeRegistration = null; } @@ -348,6 +348,8 @@ executor.stop(); executor = null; } + store.close(); + store = null; } /**