diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java index 3b011ff4e403..38ef77e85541 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/transport/netty4/Netty4Transport.java @@ -338,7 +338,9 @@ public class Netty4Transport extends TcpTransport { * side otherwise the client (node) initiates the TCP closing sequence which doesn't cause these issues. Setting this * by default from the beginning can have unexpected side-effects an should be avoided, our protocol is designed * in a way that clients close connection which is how it should be*/ - channel.config().setOption(ChannelOption.SO_LINGER, 0); + if (channel.isOpen()) { + channel.config().setOption(ChannelOption.SO_LINGER, 0); + } } } if (blocking) { diff --git a/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java b/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java index 56e017fc1f9c..29ff4219feec 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java @@ -251,7 +251,9 @@ public class MockTcpTransport extends TcpTransport * side otherwise the client (node) initiates the TCP closing sequence which doesn't cause these issues. Setting this * by default from the beginning can have unexpected side-effects an should be avoided, our protocol is designed * in a way that clients close connection which is how it should be*/ - channel.activeChannel.setSoLinger(true, 0); + if (channel.isOpen.get()) { + channel.activeChannel.setSoLinger(true, 0); + } } } } diff --git a/test/framework/src/main/java/org/elasticsearch/transport/nio/NioTransport.java b/test/framework/src/main/java/org/elasticsearch/transport/nio/NioTransport.java index 38ec361546e0..606225fd02ad 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/nio/NioTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/nio/NioTransport.java @@ -107,7 +107,9 @@ public class NioTransport extends TcpTransport { * side otherwise the client (node) initiates the TCP closing sequence which doesn't cause these issues. Setting this * by default from the beginning can have unexpected side-effects an should be avoided, our protocol is designed * in a way that clients close connection which is how it should be*/ - channel.getRawChannel().setOption(StandardSocketOptions.SO_LINGER, 0); + if (channel.isOpen()) { + channel.getRawChannel().setOption(StandardSocketOptions.SO_LINGER, 0); + } } } ArrayList futures = new ArrayList<>(channels.size());