Skip to content

Commit 118d04a

Browse files
check netty4 channel open state before trying to set SO_LINGER
1 parent 1c03716 commit 118d04a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4TcpChannel.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public void addCloseListener(ActionListener<Void> listener) {
7272

7373
@Override
7474
public void setSoLinger(int value) {
75-
channel.config().setOption(ChannelOption.SO_LINGER, value);
75+
if (channel.isOpen()) {
76+
channel.config().setOption(ChannelOption.SO_LINGER, value);
77+
}
7678
}
7779

7880
@Override

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ static void awaitConnected(DiscoveryNode discoveryNode, List<ActionFuture<Void>>
126126
static void rstAndClose(TcpChannel channel) {
127127
try {
128128
channel.setSoLinger(0);
129-
} catch (IOException | RuntimeException e) {
130-
// Depending on the implementation an already closed channel can either throw an IOException or a RuntimeException
131-
// that we ignore because we are closing with RST because of an error here.
129+
} catch (IOException e) {
130+
// We ignore the exception as we are closing with RST because of an error.
132131
}
133132
CloseableChannel.closeChannel(channel);
134133
}

0 commit comments

Comments
 (0)