Skip to content

Commit 855d27e

Browse files
authored
Ignore failures to set socket options on Mac (#44355)
Brings some temporary relief for test failures until #41071 is addressed.
1 parent 998bb47 commit 855d27e

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

libs/nio/src/main/java/org/elasticsearch/nio/ChannelFactory.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
package org.elasticsearch.nio;
2121

22+
import org.elasticsearch.common.CheckedRunnable;
23+
2224
import java.io.Closeable;
2325
import java.io.IOException;
2426
import java.io.UncheckedIOException;
2527
import java.net.InetSocketAddress;
28+
import java.net.SocketException;
2629
import java.nio.channels.ServerSocketChannel;
2730
import java.nio.channels.SocketChannel;
2831
import java.security.AccessController;
@@ -206,17 +209,30 @@ ServerSocketChannel openNioServerSocketChannel(InetSocketAddress address) throws
206209
return serverSocketChannel;
207210
}
208211

212+
private static final boolean MAC_OS_X = System.getProperty("os.name").startsWith("Mac OS X");
213+
214+
private static void setSocketOption(CheckedRunnable<SocketException> runnable) throws SocketException {
215+
try {
216+
runnable.run();
217+
} catch (SocketException e) {
218+
if (MAC_OS_X == false) {
219+
// ignore on Mac, see https://github.com/elastic/elasticsearch/issues/41071
220+
throw e;
221+
}
222+
}
223+
}
224+
209225
private void configureSocketChannel(SocketChannel channel) throws IOException {
210226
channel.configureBlocking(false);
211227
java.net.Socket socket = channel.socket();
212-
socket.setTcpNoDelay(tcpNoDelay);
213-
socket.setKeepAlive(tcpKeepAlive);
214-
socket.setReuseAddress(tcpReusedAddress);
228+
setSocketOption(() -> socket.setTcpNoDelay(tcpNoDelay));
229+
setSocketOption(() -> socket.setKeepAlive(tcpKeepAlive));
230+
setSocketOption(() -> socket.setReuseAddress(tcpReusedAddress));
215231
if (tcpSendBufferSize > 0) {
216-
socket.setSendBufferSize(tcpSendBufferSize);
232+
setSocketOption(() -> socket.setSendBufferSize(tcpSendBufferSize));
217233
}
218234
if (tcpReceiveBufferSize > 0) {
219-
socket.setSendBufferSize(tcpReceiveBufferSize);
235+
setSocketOption(() -> socket.setSendBufferSize(tcpReceiveBufferSize));
220236
}
221237
}
222238

0 commit comments

Comments
 (0)