Skip to content

Commit f24ad18

Browse files
committed
Describe closing channel in exception message (elastic#133632)
Today we report having disconnected from a node along with the root cause, typically a `SocketException`, but for troubleshooting purposes we may also need to identify the exact TCP channel which was affected by the exception. This commit adds a `NodeDisconnectedException` wrapper to add the additional details.
1 parent 7e77be8 commit f24ad18

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

modules/transport-netty4/src/internalClusterTest/java/org/elasticsearch/transport/netty4/ESLoggingHandlerIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
package org.elasticsearch.transport.netty4;
1111

1212
import org.apache.logging.log4j.Level;
13+
import org.apache.logging.log4j.core.LogEvent;
1314
import org.elasticsearch.ESNetty4IntegTestCase;
1415
import org.elasticsearch.core.TimeValue;
1516
import org.elasticsearch.test.ESIntegTestCase;
1617
import org.elasticsearch.test.MockLog;
1718
import org.elasticsearch.test.junit.annotations.TestLogging;
19+
import org.elasticsearch.transport.NodeDisconnectedException;
1820
import org.elasticsearch.transport.TcpTransport;
1921
import org.elasticsearch.transport.TransportLogger;
2022

@@ -117,7 +119,15 @@ public void testExceptionalDisconnectLogging() throws Exception {
117119
TcpTransport.class.getCanonicalName(),
118120
Level.DEBUG,
119121
".*closed transport connection \\[[1-9][0-9]*\\] to .* with age \\[[0-9]+ms\\], exception:.*"
120-
)
122+
) {
123+
@Override
124+
public void match(LogEvent event) {
125+
if (event.getThrown() instanceof NodeDisconnectedException nodeDisconnectedException
126+
&& nodeDisconnectedException.getMessage().contains("closed exceptionally: Netty4TcpChannel{")) {
127+
super.match(event);
128+
}
129+
}
130+
}
121131
);
122132

123133
final String nodeName = internalCluster().startNode();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,15 +1129,15 @@ public void onResponse(Void v) {
11291129
nodeChannels.channels.forEach(ch -> {
11301130
// Mark the channel init time
11311131
ch.getChannelStats().markAccessed(relativeMillisTime);
1132-
ch.addCloseListener(new ActionListener<Void>() {
1132+
ch.addCloseListener(new ActionListener<>() {
11331133
@Override
11341134
public void onResponse(Void ignored) {
11351135
nodeChannels.close();
11361136
}
11371137

11381138
@Override
11391139
public void onFailure(Exception e) {
1140-
nodeChannels.closeAndFail(e);
1140+
nodeChannels.closeAndFail(new NodeDisconnectedException(node, "closed exceptionally: " + ch, null, e));
11411141
}
11421142
});
11431143
});

0 commit comments

Comments
 (0)