Browse files

ISPN-2477 AsyncStore shutdown can leak threads

Partially solves ISPN-2477
* There were two exit points in the AsyncStoreCoordinator loop, and only one of them stopped the worker thread pool.
* AsyncStoreCoordinator must force the worker threads to shut down via interrupt if the initial attempt to shutdown the executor pool did not finish in time and some workers might still be running.
  • Loading branch information...
1 parent 4def486 commit 436fe5fb2bd838fcc38c92348503653acb391e1d @anistor anistor committed with danberindei Mar 27, 2013
Showing with 19 additions and 12 deletions.
  1. +19 −12 core/src/main/java/org/infinispan/loaders/decorators/AsyncStore.java
View
31 core/src/main/java/org/infinispan/loaders/decorators/AsyncStore.java
@@ -318,7 +318,7 @@ public Thread newThread(Runnable r) {
@Override
public void stop() throws CacheLoaderException {
- log.trace("Stop async store");
+ if (trace) log.tracef("Stop async store %s", this);
stateLock.writeLock(1);
state.stopped = true;
stateLock.writeUnlock();
@@ -613,15 +613,7 @@ public void run() {
State s, head, tail;
s = state;
if (shouldStop(s)) {
- // Wait for existing workers to finish
- try {
- executor.shutdown();
- executor.awaitTermination(
- shutdownTimeout, TimeUnit.MILLISECONDS);
- return;
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ return;
}
stateLock.readLock();
@@ -693,7 +685,22 @@ public void run() {
}
}
} finally {
- LogFactory.popNDC(trace);
+ try {
+ // Wait for existing workers to finish
+ boolean workersTerminated = false;
+ try {
+ executor.shutdown();
+ workersTerminated = executor.awaitTermination(shutdownTimeout, TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ if (!workersTerminated) {
+ // if the worker threads did not finish cleanly in the allotted time then we try to interrupt them to shut down
+ executor.shutdownNow();
+ }
+ } finally {
+ LogFactory.popNDC(trace);
+ }
}
}
@@ -740,4 +747,4 @@ private void retryWork(int maxRetries) {
log.unableToProcessAsyncModifications(maxRetries);
}
}
-}
+}

0 comments on commit 436fe5f

Please sign in to comment.