Skip to content

Commit c83f112

Browse files
authored
Stop responding to ping requests before master abdication (#27329)
When the current master node is shutting down, it sends a leave request to the other nodes so that they can eagerly start a fresh master election. Unfortunately, it was still possible for the master node that was shutting down to respond to ping requests, possibly influencing the election decision as it still appeared as an active master in the ping responses. This commit ensures that UnicastZenPing does not respond to ping requests once it's been closed. ZenDiscovery.doStop() continues to ensure that the pinging component is first closed before it triggers a master election. Closes #27328
1 parent 91a23de commit c83f112

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

core/src/main/java/org/elasticsearch/discovery/zen/UnicastZenPing.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ public void handleResponse(UnicastPingResponse response) {
575575

576576
@Override
577577
public void handleException(TransportException exp) {
578-
if (exp instanceof ConnectTransportException || exp.getCause() instanceof ConnectTransportException) {
578+
if (exp instanceof ConnectTransportException || exp.getCause() instanceof ConnectTransportException ||
579+
exp.getCause() instanceof AlreadyClosedException) {
579580
// ok, not connected...
580581
logger.trace((Supplier<?>) () -> new ParameterizedMessage("failed to connect to {}", node), exp);
581582
} else if (closed == false) {
@@ -608,6 +609,9 @@ class UnicastPingRequestHandler implements TransportRequestHandler<UnicastPingRe
608609

609610
@Override
610611
public void messageReceived(UnicastPingRequest request, TransportChannel channel) throws Exception {
612+
if (closed) {
613+
throw new AlreadyClosedException("node is shutting down");
614+
}
611615
if (request.pingResponse.clusterName().equals(clusterName)) {
612616
channel.sendResponse(handlePingRequest(request));
613617
} else {

core/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ protected Version getVersion() {
258258
assertPingCount(handleD, handleA, 0);
259259
assertPingCount(handleD, handleB, 0);
260260
assertPingCount(handleD, handleC, 3);
261+
262+
zenPingC.close();
263+
handleD.counters.clear();
264+
logger.info("ping from UZP_D after closing UZP_C");
265+
pingResponses = zenPingD.pingAndWait().toList();
266+
// check that node does not respond to pings anymore after the ping service has been closed
267+
assertThat(pingResponses.size(), equalTo(0));
268+
assertPingCount(handleD, handleA, 0);
269+
assertPingCount(handleD, handleB, 0);
270+
assertPingCount(handleD, handleC, 3);
261271
}
262272

263273
public void testUnknownHostNotCached() throws ExecutionException, InterruptedException {

0 commit comments

Comments
 (0)