Skip to content

Commit f02582d

Browse files
committed
Reduce a bind failure to trace logging (#46891)
Due to recent changes in the nio transport, a failure to bind the server channel has started to be logged at an error level. This exception leads to an automatic retry on a different port, so it should only be logged at a trace level.
1 parent 22dade8 commit f02582d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

libs/nio/src/main/java/org/elasticsearch/nio/ServerChannelContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.common.concurrent.CompletableContext;
2323

2424
import java.io.IOException;
25+
import java.net.BindException;
2526
import java.net.InetSocketAddress;
2627
import java.net.ServerSocket;
2728
import java.nio.channels.ServerSocketChannel;
@@ -78,7 +79,8 @@ protected void register() throws IOException {
7879
rawChannel.bind(localAddress);
7980
bindContext.complete(null);
8081
} catch (IOException e) {
81-
IOException exception = new IOException("Failed to bind server socket channel {localAddress=" + localAddress + "}.", e);
82+
BindException exception = new BindException("Failed to bind server socket channel {localAddress=" + localAddress + "}.");
83+
exception.initCause(e);
8284
bindContext.completeExceptionally(exception);
8385
throw exception;
8486
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ public void onException(TcpChannel channel, Exception e) {
618618
}
619619

620620
protected void onServerException(TcpServerChannel channel, Exception e) {
621-
logger.error(new ParameterizedMessage("exception from server channel caught on transport layer [channel={}]", channel), e);
621+
if (e instanceof BindException) {
622+
logger.trace(() -> new ParameterizedMessage("bind exception from server channel caught on transport layer [{}]", channel), e);
623+
} else {
624+
logger.error(new ParameterizedMessage("exception from server channel caught on transport layer [{}]", channel), e);
625+
}
622626
}
623627

624628
protected void serverAcceptedChannel(TcpChannel channel) {

0 commit comments

Comments
 (0)