Skip to content

Commit

Permalink
ZOOKEEPER-3240: Close socket on Learner shutdown to avoid dangling so…
Browse files Browse the repository at this point in the history
…cket
  • Loading branch information
Brian Nixon committed Jun 21, 2019
1 parent 92257ef commit 381889d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ void followLeader() throws InterruptedException {
}
} catch (Exception e) {
LOG.warn("Exception when following the leader", e);
try {
sock.close();
} catch (IOException e1) {
e1.printStackTrace();
}
closeSocket();

// clear pending revalidations
pendingRevalidations.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ public void shutdown() {
self.setZooKeeperServer(null);
self.closeAllConnections();
self.adminServer.setZooKeeperServer(null);
closeSocket();
// shutdown previous zookeeper
if (zk != null) {
zk.shutdown();
Expand All @@ -682,4 +683,14 @@ public void shutdown() {
boolean isRunning() {
return self.isRunning() && zk.isRunning();
}

void closeSocket() {
try {
if (sock != null && !sock.isClosed()) {
sock.close();
}
} catch (IOException e) {
LOG.warn("Ignoring error closing connection to leader", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ void observeLeader() throws Exception {
}
} catch (Exception e) {
LOG.warn("Exception when observing the leader", e);
try {
sock.close();
} catch (IOException e1) {
e1.printStackTrace();
}
closeSocket();

// clear pending revalidations
pendingRevalidations.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,10 @@ public void testFailedTxnAsPartOfQuorumLoss() throws Exception {
int leader = servers.findLeader();
Map<Long, Proposal> outstanding = servers.mt[leader].main.quorumPeer.leader.outstandingProposals;
// increase the tick time to delay the leader going to looking
int previousTick = servers.mt[leader].main.quorumPeer.tickTime;
servers.mt[leader].main.quorumPeer.tickTime = LEADER_TIMEOUT_MS;
// let the previous tick on the leader exhaust itself so the new tick time takes effect
Thread.sleep(previousTick);
LOG.warn("LEADER {}", leader);

for (int i = 0; i < SERVER_COUNT; i++) {
Expand Down

0 comments on commit 381889d

Please sign in to comment.