Skip to content

Commit 23dde94

Browse files
committed
Describe closing channel in exception message (#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 3cc1e5f commit 23dde94

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
@@ -1134,15 +1134,15 @@ public void onResponse(Void v) {
11341134
nodeChannels.channels.forEach(ch -> {
11351135
// Mark the channel init time
11361136
ch.getChannelStats().markAccessed(relativeMillisTime);
1137-
ch.addCloseListener(new ActionListener<Void>() {
1137+
ch.addCloseListener(new ActionListener<>() {
11381138
@Override
11391139
public void onResponse(Void ignored) {
11401140
nodeChannels.close();
11411141
}
11421142

11431143
@Override
11441144
public void onFailure(Exception e) {
1145-
nodeChannels.closeAndFail(e);
1145+
nodeChannels.closeAndFail(new NodeDisconnectedException(node, "closed exceptionally: " + ch, null, e));
11461146
}
11471147
});
11481148
});

0 commit comments

Comments
 (0)