Index: oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java =================================================================== --- oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java (revision 1772686) +++ oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java (working copy) @@ -48,6 +48,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import com.google.common.io.Closer; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; @@ -356,21 +357,6 @@ @Deactivate public void deactivate() { unregisterNodeStore(); - - synchronized (this) { - if (observerTracker != null) { - observerTracker.stop(); - } - if (gcMonitor != null) { - gcMonitor.stop(); - } - segmentNodeStore = null; - - if (store != null) { - store.close(); - store = null; - } - } } private synchronized void registerNodeStore() throws IOException { @@ -676,19 +662,49 @@ } private void unregisterNodeStore() { - new CompositeRegistration(registrations).unregister(); + CompositeRegistration registrations; + ServiceRegistration providerRegistration; + ServiceRegistration storeRegistration; + WhiteboardExecutor executor; + ObserverTracker observerTracker; + GCMonitorTracker gcMonitor; + FileStore store; + synchronized (this) { + registrations = new CompositeRegistration(new ArrayList<>(this.registrations)); + this.registrations.clear(); + providerRegistration = this.providerRegistration; + this.providerRegistration = null; + storeRegistration = this.storeRegistration; + this.storeRegistration = null; + executor = this.executor; + this.executor = null; + observerTracker = this.observerTracker; + this.observerTracker = null; + gcMonitor = this.gcMonitor; + this.gcMonitor = null; + store = this.store; + this.store = null; + this.segmentNodeStore = null; + } + registrations.unregister(); if (providerRegistration != null) { providerRegistration.unregister(); - providerRegistration = null; } if (storeRegistration != null) { storeRegistration.unregister(); - storeRegistration = null; } if (executor != null) { executor.stop(); - executor = null; } + if (observerTracker != null) { + observerTracker.stop(); + } + if (gcMonitor != null) { + gcMonitor.stop(); + } + if (store != null) { + store.close(); + } } private File getBaseDirectory() {