From cb8b1cd32ba7351db37412b635ebb673d4f647b8 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Sun, 26 Jan 2014 14:51:55 +0000 Subject: [PATCH] SOLR-5577: Harden leaking Timer thread. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1561497 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/common/cloud/ConnectionManager.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java index 961ed355975..d09660cb5c0 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ConnectionManager.java @@ -72,8 +72,8 @@ public class ConnectionManager implements Watcher { private synchronized void disconnected() { cancelTimer(); if (!isClosed) { - disconnectedTimer = new Timer(true); - disconnectedTimer.schedule(new TimerTask() { + Timer newDcTimer = new Timer(true); + newDcTimer.schedule(new TimerTask() { @Override public void run() { @@ -84,7 +84,16 @@ public class ConnectionManager implements Watcher { if (isClosed) { // we might have closed after getting by isClosed // and before starting the new timer - cancelTimer(); + newDcTimer.cancel(); + } else { + disconnectedTimer = newDcTimer; + if (isClosed) { + // now deal with we may have been closed after getting + // by isClosed but before setting disconnectedTimer - + // if close happens after isClosed check this time, it + // will handle stopping the timer + cancelTimer(); + } } } connected = false; @@ -196,7 +205,7 @@ public class ConnectionManager implements Watcher { } // we use a volatile rather than sync - // to avoid deadlock on shutdown + // to avoid possible deadlock on shutdown public void close() { this.isClosed = true; this.likelyExpired = true;