Skip to content

Commit 1a92696

Browse files
daschlMichael Nitschinger
authored andcommitted
SPY-171: More robust shutdown handling characteristics.
Motivation ---------- It has been reported several times that the IO thread kept lingering around even after a shutdown() call. Modifications ------------- Since its run() method is kept alive by the "running" variable, the code now makes sure to always set it to false, even if an exception occurs during the connection shutdown process. Also, a slightly misleading IOException has been removed in favor of just silently moving on if shutdown is in progress. Result ------ More stable and predictable shutdown behavior. Change-Id: I99f3effbbb20a78a2705ee7f3f839e9753fb2a4a Reviewed-on: http://review.couchbase.org/37724 Reviewed-by: Michael Nitschinger <michael.nitschinger@couchbase.com> Tested-by: Michael Nitschinger <michael.nitschinger@couchbase.com>
1 parent 4aae4c5 commit 1a92696

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/main/java/net/spy/memcached/MemcachedConnection.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ private boolean selectorsMakeSense() {
389389
*/
390390
public void handleIO() throws IOException {
391391
if (shutDown) {
392-
throw new IOException("No IO while shut down");
392+
getLogger().debug("No IO while shut down.");
393+
return;
393394
}
394395

395396
handleInputQueue();
@@ -1285,23 +1286,26 @@ public CountDownLatch broadcastOperation(final BroadcastOpFactory of,
12851286
*/
12861287
public void shutdown() throws IOException {
12871288
shutDown = true;
1288-
1289-
Selector s = selector.wakeup();
1290-
assert s == selector : "Wakeup returned the wrong selector.";
1291-
for (MemcachedNode node : locator.getAll()) {
1292-
if (node.getChannel() != null) {
1293-
node.getChannel().close();
1294-
node.setSk(null);
1295-
if (node.getBytesRemainingToWrite() > 0) {
1296-
getLogger().warn("Shut down with %d bytes remaining to write",
1289+
try {
1290+
Selector s = selector.wakeup();
1291+
assert s == selector : "Wakeup returned the wrong selector.";
1292+
for (MemcachedNode node : locator.getAll()) {
1293+
if (node.getChannel() != null) {
1294+
node.getChannel().close();
1295+
node.setSk(null);
1296+
if (node.getBytesRemainingToWrite() > 0) {
1297+
getLogger().warn("Shut down with %d bytes remaining to write",
12971298
node.getBytesRemainingToWrite());
1299+
}
1300+
getLogger().debug("Shut down channel %s", node.getChannel());
12981301
}
1299-
getLogger().debug("Shut down channel %s", node.getChannel());
13001302
}
1303+
1304+
selector.close();
1305+
getLogger().debug("Shut down selector %s", selector);
1306+
} finally {
1307+
running = false;
13011308
}
1302-
running = false;
1303-
selector.close();
1304-
getLogger().debug("Shut down selector %s", selector);
13051309
}
13061310

13071311
@Override

0 commit comments

Comments
 (0)