Skip to content

Commit 4b0eeba

Browse files
committed
Suppress warning on request if transport not ready
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 elastic#44939 Relates elastic#16746 Closes elastic#61356
1 parent 5f478ac commit 4b0eeba

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
@@ -618,6 +618,9 @@ static void handleException(TcpChannel channel, Exception e, Lifecycle lifecycle
618618
} else if (e instanceof StreamCorruptedException) {
619619
logger.warn(() -> new ParameterizedMessage("{}, [{}], closing connection", e.getMessage(), channel));
620620
CloseableChannel.closeChannel(channel);
621+
} else if (e instanceof TransportNotReadyException) {
622+
logger.debug(() -> new ParameterizedMessage("{} on [{}], closing connection", e.getMessage(), channel));
623+
CloseableChannel.closeChannel(channel);
621624
} else {
622625
logger.warn(() -> new ParameterizedMessage("exception caught on transport layer [{}], closing connection", channel), e);
623626
// 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.
14+
*/
15+
public class TransportNotReadyException extends TransportException {
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
@@ -928,7 +928,7 @@ public <Request extends TransportRequest> void registerRequestHandler(String act
928928
@Override
929929
public void onRequestReceived(long requestId, String action) {
930930
if (handleIncomingRequests.get() == false) {
931-
throw new IllegalStateException("transport not ready yet to handle incoming requests");
931+
throw new TransportNotReadyException();
932932
}
933933
if (tracerLog.isTraceEnabled() && shouldTraceAction(action)) {
934934
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)