Add comment to TCP transport impls why we set SO_LINGER on close

This commit is contained in:
Simon Willnauer 2017-09-28 13:05:44 +02:00
parent f9f8856d89
commit 25d6778d31
3 changed files with 15 additions and 0 deletions

View File

@ -334,6 +334,11 @@ public class Netty4Transport extends TcpTransport<Channel> {
protected void closeChannels(final List<Channel> channels, boolean blocking, boolean closingTransport) throws IOException {
if (closingTransport) {
for (Channel channel : channels) {
/* We set SO_LINGER timeout to 0 to ensure that when we shutdown the node we don't have a gazillion connections sitting
* in TIME_WAIT to free up resources quickly. This is really the only part where we close the connection from the server
* 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);
}
}

View File

@ -246,6 +246,11 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
if (closingTransport) {
for (MockChannel channel : channels) {
if (channel.activeChannel != null) {
/* We set SO_LINGER timeout to 0 to ensure that when we shutdown the node we don't have a gazillion connections sitting
* in TIME_WAIT to free up resources quickly. This is really the only part where we close the connection from the server
* 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);
}
}

View File

@ -102,6 +102,11 @@ public class NioTransport extends TcpTransport<NioChannel> {
protected void closeChannels(List<NioChannel> channels, boolean blocking, boolean closingTransport) throws IOException {
if (closingTransport) {
for (NioChannel channel : channels) {
/* We set SO_LINGER timeout to 0 to ensure that when we shutdown the node we don't have a gazillion connections sitting
* in TIME_WAIT to free up resources quickly. This is really the only part where we close the connection from the server
* 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);
}
}