Skip to content

Commit

Permalink
Remove TcpChannel#setSoLinger method (#35924) (#35952)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks committed Nov 27, 2018
1 parent 5c5914b commit f2deb9a
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 52 deletions.
Expand Up @@ -20,9 +20,7 @@
package org.elasticsearch.transport.netty4;

import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPromise;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
Expand All @@ -32,7 +30,6 @@
import org.elasticsearch.transport.TcpChannel;
import org.elasticsearch.transport.TransportException;

import java.io.IOException;
import java.net.InetSocketAddress;

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

@Override
public void setSoLinger(int value) throws IOException {
if (channel.isOpen()) {
try {
channel.config().setOption(ChannelOption.SO_LINGER, value);
} catch (ChannelException e) {
throw new IOException(e);
}
}
}

@Override
public boolean isOpen() {
return channel.isOpen();
Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.network.CloseableChannel;

import java.io.IOException;
import java.net.InetSocketAddress;


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

/**
* This sets the low level socket option {@link java.net.StandardSocketOptions} SO_LINGER on a channel.
*
* @param value to set for SO_LINGER
* @throws IOException that can be throw by the low level socket implementation
*/
void setSoLinger(int value) throws IOException;

/**
* Returns the local address for this channel.
*
Expand Down
18 changes: 0 additions & 18 deletions server/src/main/java/org/elasticsearch/transport/TcpTransport.java
Expand Up @@ -348,24 +348,6 @@ protected void innerOnFailure(Exception e) {
public void close() {
if (isClosing.compareAndSet(false, true)) {
try {
if (lifecycle.stopped()) {
/* 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*/

channels.forEach(c -> {
try {
c.setSoLinger(0);
} catch (IOException e) {
logger.warn(new ParameterizedMessage("unexpected exception when setting SO_LINGER on channel {}", c), e);
}
});
}

boolean block = lifecycle.stopped() && Transports.isTransportThread(Thread.currentThread()) == false;
CloseableChannel.closeChannels(channels, block);
} finally {
Expand Down
Expand Up @@ -273,10 +273,6 @@ public void addCloseListener(ActionListener<Void> listener) {
public void addConnectListener(ActionListener<Void> listener) {
}

@Override
public void setSoLinger(int value) throws IOException {
}

@Override
public boolean isOpen() {
return false;
Expand Down
Expand Up @@ -399,13 +399,6 @@ public void addConnectListener(ActionListener<Void> listener) {
connectFuture.addListener(ActionListener.toBiConsumer(listener));
}

@Override
public void setSoLinger(int value) throws IOException {
if (activeChannel != null && activeChannel.isClosed() == false) {
activeChannel.setSoLinger(true, value);
}
}

@Override
public boolean isOpen() {
return isOpen.get();
Expand Down

0 comments on commit f2deb9a

Please sign in to comment.