Skip to content
Browse files

Fix race condition in client socket close. Solves subtle timeout race…

… in previous fix
  • Loading branch information...
1 parent 161ec39 commit 98b873edd714994c387645815e919e1382d31291 @ctasada committed Apr 4, 2012
Showing with 8 additions and 5 deletions.
  1. +8 −5 src/java/voldemort/store/socket/SocketStore.java
View
13 src/java/voldemort/store/socket/SocketStore.java
@@ -219,7 +219,7 @@ public String getName() {
}
public void close() throws VoldemortException {
- // don't close the socket pool, it is shared
+ // don't close the socket pool, it is shared
}
/**
@@ -240,29 +240,32 @@ public void close() throws VoldemortException {
private <T> T request(ClientRequest<T> delegate, String operationName) {
ClientRequestExecutor clientRequestExecutor = pool.checkout(destination);
+ BlockingClientRequest<T> blockingClientRequest = null;
try {
- BlockingClientRequest<T> blockingClientRequest = new BlockingClientRequest<T>(delegate,
- timeoutMs);
+ blockingClientRequest = new BlockingClientRequest<T>(delegate, timeoutMs);
clientRequestExecutor.addClientRequest(blockingClientRequest, timeoutMs);
blockingClientRequest.await();
return blockingClientRequest.getResult();
} catch(InterruptedException e) {
- clientRequestExecutor.close();
throw new UnreachableStoreException("Failure in " + operationName + " on "
+ destination + ": " + e.getMessage(), e);
} catch(IOException e) {
clientRequestExecutor.close();
throw new UnreachableStoreException("Failure in " + operationName + " on "
+ destination + ": " + e.getMessage(), e);
} finally {
+ if(blockingClientRequest != null && !blockingClientRequest.isComplete()) {
+ // close the executor if we timed out
+ clientRequestExecutor.close();
+ }
pool.checkin(destination, clientRequestExecutor);
}
}
/**
* This method handles submitting and then waiting for the request from the
* server. It uses the ClientRequest API to actually write the request and
- * then read back the response. This implementation will block for a
+ * then read back the response. This implementation will not block for a
* response from the server.
*
* @param <T> Return type

0 comments on commit 98b873e

Please sign in to comment.
Something went wrong with that request. Please try again.