Skip to content

Commit 0bebaee

Browse files
committed
Suppress warning on request if transport not ready (#69686)
Today we bind to our transport address(es) very early in the startup of a node so that we know the addresses to which we're bound, even though we are not yet ready to handle any requests. If we receive a request in this state then we throw an `IllegalStateException` which results in a logged warning and the connection being closed. In practice, this happens straight away since the first request on the connection, the handshake, is sent as soon as it's open. This commit introduces a `TransportNotReadyException` for this specific case, and suppresses the noisy logging on such exceptions. Relates #44939 Relates #16746 Closes #61356
1 parent 2298185 commit 0bebaee

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

server/src/main/java/org/elasticsearch/transport/TcpTransport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,9 @@ static void handleException(TcpChannel channel, Exception e, Lifecycle lifecycle
633633
} else if (e instanceof StreamCorruptedException) {
634634
logger.warn(() -> new ParameterizedMessage("{}, [{}], closing connection", e.getMessage(), channel));
635635
CloseableChannel.closeChannel(channel);
636+
} else if (e instanceof TransportNotReadyException) {
637+
logger.debug(() -> new ParameterizedMessage("{} on [{}], closing connection", e.getMessage(), channel));
638+
CloseableChannel.closeChannel(channel);
636639
} else {
637640
logger.warn(() -> new ParameterizedMessage("exception caught on transport layer [{}], closing connection", channel), e);
638641
// close the channel, which will cause a node to be disconnected if relevant
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.transport;
10+
11+
/**
12+
* Exception indicating that the {@link TransportService} received a request before it was ready to handle it, so the request should be
13+
* rejected and the connection closed. Never goes over the wire, so it's just a {@link RuntimeException}.
14+
*/
15+
public class TransportNotReadyException extends RuntimeException {
16+
public TransportNotReadyException() {
17+
super("transport not ready yet to handle incoming requests");
18+
}
19+
20+
@Override
21+
public Throwable fillInStackTrace() {
22+
return this; // stack trace is uninteresting
23+
}
24+
}

server/src/main/java/org/elasticsearch/transport/TransportService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ public <Request extends TransportRequest> void registerRequestHandler(String act
10431043
@Override
10441044
public void onRequestReceived(long requestId, String action) {
10451045
if (handleIncomingRequests.get() == false) {
1046-
throw new IllegalStateException("transport not ready yet to handle incoming requests");
1046+
throw new TransportNotReadyException();
10471047
}
10481048
if (tracerLog.isTraceEnabled() && shouldTraceAction(action)) {
10491049
tracerLog.trace("[{}][{}] received request", requestId, action);

server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ public void testExceptionHandling() throws IllegalAccessException {
368368
testExceptionHandling(new StreamCorruptedException("simulated"),
369369
new MockLogAppender.SeenEventExpectation("message", "org.elasticsearch.transport.TcpTransport",
370370
Level.WARN, "simulated, [*], closing connection"));
371+
testExceptionHandling(new TransportNotReadyException(),
372+
new MockLogAppender.SeenEventExpectation("message", "org.elasticsearch.transport.TcpTransport",
373+
Level.DEBUG, "transport not ready yet to handle incoming requests on [*], closing connection"));
371374
}
372375

373376
private void testExceptionHandling(Exception exception,

0 commit comments

Comments
 (0)