Skip to content

Commit

Permalink
Don't set SO_REUSEPORT on Windows (hazelcast#23947) [HZ-2213]
Browse files Browse the repository at this point in the history
SO_REUSEADDR flag works as expected on POSIX platforms, but will cause indeterminate behaviors on Windows sockets.

See:
- jetty/jetty.project#6661 (comment)
- learn.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse#using-so_reuseaddr
  • Loading branch information
ldziedziul committed Sep 6, 2023
1 parent 9c67922 commit c607ded
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -18,12 +18,14 @@

import com.hazelcast.internal.tpcengine.Option;
import com.hazelcast.internal.tpcengine.net.AsyncSocketOptions;
import com.hazelcast.internal.tpcengine.util.OS;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.channels.ServerSocketChannel;
import java.util.Set;

import static com.hazelcast.internal.tpcengine.util.Preconditions.checkNotNull;

Expand All @@ -32,6 +34,7 @@
*/
public class NioAsyncServerSocketOptions implements AsyncSocketOptions {

private static final Set<SocketOption<?>> WINDOWS_UNSUPPORTED_OPTIONS = Set.of(StandardSocketOptions.SO_REUSEPORT);
private final ServerSocketChannel serverSocketChannel;

NioAsyncServerSocketOptions(ServerSocketChannel serverSocketChannel) {
Expand Down Expand Up @@ -59,7 +62,13 @@ public boolean isSupported(Option option) {
}

private boolean isSupported(SocketOption socketOption) {
return socketOption != null && serverSocketChannel.supportedOptions().contains(socketOption);
if (socketOption == null) {
return false;
}
if (OS.isWindows() && WINDOWS_UNSUPPORTED_OPTIONS.contains(socketOption)) {
return false;
}
return serverSocketChannel.supportedOptions().contains(socketOption);
}

@Override
Expand Down

0 comments on commit c607ded

Please sign in to comment.