Skip to content

Commit f2deb9a

Browse files
authored
Remove TcpChannel#setSoLinger method (#35924) (#35952)
This commit removes the dedicated `setSoLinger` method. This simplifies the `TcpChannel` interface. This method has very little effect as the SO_LINGER is not set prior to the channels being closed in the abstract transport test case.
1 parent 5c5914b commit f2deb9a

File tree

5 files changed

+0
-52
lines changed

5 files changed

+0
-52
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
package org.elasticsearch.transport.netty4;
2121

2222
import io.netty.channel.Channel;
23-
import io.netty.channel.ChannelException;
2423
import io.netty.channel.ChannelFuture;
25-
import io.netty.channel.ChannelOption;
2624
import io.netty.channel.ChannelPromise;
2725
import org.elasticsearch.ExceptionsHelper;
2826
import org.elasticsearch.action.ActionListener;
@@ -32,7 +30,6 @@
3230
import org.elasticsearch.transport.TcpChannel;
3331
import org.elasticsearch.transport.TransportException;
3432

35-
import java.io.IOException;
3633
import java.net.InetSocketAddress;
3734

3835
public class Netty4TcpChannel implements TcpChannel {
@@ -95,17 +92,6 @@ public void addConnectListener(ActionListener<Void> listener) {
9592
connectContext.addListener(ActionListener.toBiConsumer(listener));
9693
}
9794

98-
@Override
99-
public void setSoLinger(int value) throws IOException {
100-
if (channel.isOpen()) {
101-
try {
102-
channel.config().setOption(ChannelOption.SO_LINGER, value);
103-
} catch (ChannelException e) {
104-
throw new IOException(e);
105-
}
106-
}
107-
}
108-
10995
@Override
11096
public boolean isOpen() {
11197
return channel.isOpen();

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.common.bytes.BytesReference;
2424
import org.elasticsearch.common.network.CloseableChannel;
2525

26-
import java.io.IOException;
2726
import java.net.InetSocketAddress;
2827

2928

@@ -39,14 +38,6 @@ public interface TcpChannel extends CloseableChannel {
3938
*/
4039
String getProfile();
4140

42-
/**
43-
* This sets the low level socket option {@link java.net.StandardSocketOptions} SO_LINGER on a channel.
44-
*
45-
* @param value to set for SO_LINGER
46-
* @throws IOException that can be throw by the low level socket implementation
47-
*/
48-
void setSoLinger(int value) throws IOException;
49-
5041
/**
5142
* Returns the local address for this channel.
5243
*

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -348,24 +348,6 @@ protected void innerOnFailure(Exception e) {
348348
public void close() {
349349
if (isClosing.compareAndSet(false, true)) {
350350
try {
351-
if (lifecycle.stopped()) {
352-
/* We set SO_LINGER timeout to 0 to ensure that when we shutdown the node we don't
353-
* have a gazillion connections sitting in TIME_WAIT to free up resources quickly.
354-
* This is really the only part where we close the connection from the server side
355-
* otherwise the client (node) initiates the TCP closing sequence which doesn't cause
356-
* these issues. Setting this by default from the beginning can have unexpected
357-
* side-effects an should be avoided, our protocol is designed in a way that clients
358-
* close connection which is how it should be*/
359-
360-
channels.forEach(c -> {
361-
try {
362-
c.setSoLinger(0);
363-
} catch (IOException e) {
364-
logger.warn(new ParameterizedMessage("unexpected exception when setting SO_LINGER on channel {}", c), e);
365-
}
366-
});
367-
}
368-
369351
boolean block = lifecycle.stopped() && Transports.isTransportThread(Thread.currentThread()) == false;
370352
CloseableChannel.closeChannels(channels, block);
371353
} finally {

server/src/test/java/org/elasticsearch/transport/TcpTransportTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,6 @@ public void addCloseListener(ActionListener<Void> listener) {
273273
public void addConnectListener(ActionListener<Void> listener) {
274274
}
275275

276-
@Override
277-
public void setSoLinger(int value) throws IOException {
278-
}
279-
280276
@Override
281277
public boolean isOpen() {
282278
return false;

test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,6 @@ public void addConnectListener(ActionListener<Void> listener) {
399399
connectFuture.addListener(ActionListener.toBiConsumer(listener));
400400
}
401401

402-
@Override
403-
public void setSoLinger(int value) throws IOException {
404-
if (activeChannel != null && activeChannel.isClosed() == false) {
405-
activeChannel.setSoLinger(true, value);
406-
}
407-
}
408-
409402
@Override
410403
public boolean isOpen() {
411404
return isOpen.get();

0 commit comments

Comments
 (0)