Check channel i open before setting SO_LINGER (#26857)

This commit fixes a #26855. Right now we set SO_LINGER to 0 if we are
stopping the transport. This can throw a ChannelClosedException if the
raw channel is already closed. We have a number of scenarios where it is
possible this could be called with a channel that is already closed.
This commit fixes the issue be checking that the channel is not closed
before attempting to set the socket option.
This commit is contained in:
Tim Brooks 2017-10-02 15:09:52 -06:00 committed by GitHub
parent dbea83a1d0
commit d80ad7f097
3 changed files with 9 additions and 3 deletions

View File

@ -338,9 +338,11 @@ public class Netty4Transport extends TcpTransport<Channel> {
* 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*/
if (channel.isOpen()) {
channel.config().setOption(ChannelOption.SO_LINGER, 0);
}
}
}
if (blocking) {
Netty4Utils.closeChannels(channels);
} else {

View File

@ -251,10 +251,12 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
* 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*/
if (channel.isOpen.get()) {
channel.activeChannel.setSoLinger(true, 0);
}
}
}
}
IOUtils.close(channels);
}

View File

@ -107,9 +107,11 @@ public class NioTransport extends TcpTransport<NioChannel> {
* 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*/
if (channel.isOpen()) {
channel.getRawChannel().setOption(StandardSocketOptions.SO_LINGER, 0);
}
}
}
ArrayList<CloseFuture> futures = new ArrayList<>(channels.size());
for (final NioChannel channel : channels) {
if (channel != null && channel.isOpen()) {