Ignore failures to set socket options on Mac (#44355)

Brings some temporary relief for test failures until #41071 is addressed.
This commit is contained in:
Yannick Welsch 2019-07-17 17:33:40 +02:00
parent f78e64e3e2
commit c8b66c549d
2 changed files with 21 additions and 5 deletions

View File

@ -19,10 +19,13 @@
package org.elasticsearch.nio; package org.elasticsearch.nio;
import org.elasticsearch.common.CheckedRunnable;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketException;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.security.AccessController; import java.security.AccessController;
@ -206,17 +209,30 @@ public abstract class ChannelFactory<ServerSocket extends NioServerSocketChannel
return serverSocketChannel; return serverSocketChannel;
} }
private static final boolean MAC_OS_X = System.getProperty("os.name").startsWith("Mac OS X");
private static void setSocketOption(CheckedRunnable<SocketException> runnable) throws SocketException {
try {
runnable.run();
} catch (SocketException e) {
if (MAC_OS_X == false) {
// ignore on Mac, see https://github.com/elastic/elasticsearch/issues/41071
throw e;
}
}
}
private void configureSocketChannel(SocketChannel channel) throws IOException { private void configureSocketChannel(SocketChannel channel) throws IOException {
channel.configureBlocking(false); channel.configureBlocking(false);
java.net.Socket socket = channel.socket(); java.net.Socket socket = channel.socket();
socket.setTcpNoDelay(tcpNoDelay); setSocketOption(() -> socket.setTcpNoDelay(tcpNoDelay));
socket.setKeepAlive(tcpKeepAlive); setSocketOption(() -> socket.setKeepAlive(tcpKeepAlive));
socket.setReuseAddress(tcpReusedAddress); setSocketOption(() -> socket.setReuseAddress(tcpReusedAddress));
if (tcpSendBufferSize > 0) { if (tcpSendBufferSize > 0) {
socket.setSendBufferSize(tcpSendBufferSize); setSocketOption(() -> socket.setSendBufferSize(tcpSendBufferSize));
} }
if (tcpReceiveBufferSize > 0) { if (tcpReceiveBufferSize > 0) {
socket.setSendBufferSize(tcpReceiveBufferSize); setSocketOption(() -> socket.setSendBufferSize(tcpReceiveBufferSize));
} }
} }