Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some SocketOptions not supported on Windows #6661

Closed
joakime opened this issue Aug 24, 2021 · 7 comments · Fixed by #6663
Closed

Some SocketOptions not supported on Windows #6661

joakime opened this issue Aug 24, 2021 · 7 comments · Fixed by #6663
Assignees
Labels
Bug For general bugs on Jetty side Microsoft Windows For issues unique to Microsoft Windows

Comments

@joakime
Copy link
Contributor

joakime commented Aug 24, 2021

Jetty version(s)
10.0.x

Java version/vendor (use: java -version)
11.0.12

OS type/version
Windows 10

Description

The recent work on Issue #6372 is not compatible with Windows 10.

Caused by: java.lang.UnsupportedOperationException: 'SO_REUSEPORT' not supported
	at java.base/sun.nio.ch.ServerSocketChannelImpl.setOption(ServerSocketChannelImpl.java:151)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:338)
@joakime joakime added Bug For general bugs on Jetty side Microsoft Windows For issues unique to Microsoft Windows labels Aug 24, 2021
@joakime joakime added this to To do in Jetty 10.0.7/11.0.7 FROZEN via automation Aug 24, 2021
@joakime
Copy link
Contributor Author

joakime commented Aug 24, 2021

Opened PR #6663

@joakime joakime moved this from To do to Review in progress in Jetty 10.0.7/11.0.7 FROZEN Aug 24, 2021
@joakime joakime changed the title SocketOptions not supported on Windows Some SocketOptions not supported on Windows Aug 24, 2021
@joakime joakime self-assigned this Aug 24, 2021
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Review in progress to Done Aug 25, 2021
joakime added a commit that referenced this issue Aug 25, 2021
…t-setoptions

Issue #6661 - Make ServerConnector socket options setting optional
@delanym
Copy link

delanym commented Oct 17, 2022

Did this go in? I'm still getting this on Jetty 11.0.12

java.lang.UnsupportedOperationException: 'SO_REUSEPORT' not supported
    at java.base/sun.nio.ch.ServerSocketChannelImpl.setOption(ServerSocketChannelImpl.java:151)
    at org.eclipse.jetty.server.ServerConnector.setSocketOption(ServerConnector.java:355)

@sbordet
Copy link
Contributor

sbordet commented Oct 17, 2022

The exception is logged at DEBUG level since 11.0.7.
If you have DEBUG logs enabled, you will "get" it.
Otherwise, you have to be more specific about where you "get" it.

@joakime
Copy link
Contributor Author

joakime commented Oct 17, 2022

@delanym That is Jetty reporting (via debug level logging event) that your JVM is unable to support SO_REUSEPORT on that Socket type.

Here's the code in 11.0.12 ...

https://github.com/eclipse/jetty.project/blob/jetty-11.0.12/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java#L351-L362

And it being used to attempt to set SO_REUSEPORT

https://github.com/eclipse/jetty.project/blob/jetty-11.0.12/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java#L335

@delanym
Copy link

delanym commented Oct 17, 2022

Thanks I'll see whats going on with the JDK. From my miserable understanding of Java serving up a stack exception is a costly affair so i'd like to avoid that, and reuse the port if possible.

@joakime
Copy link
Contributor Author

joakime commented Oct 17, 2022

From my miserable understanding of Java serving up a stack exception is a costly affair so i'd like to avoid that

This happens on the ServerConnector once only when the Listening socket is setup to accept incoming socket connections.
If you were using something like Java 1.4, it could be costly. But that's not been true for a long time. especially so with Java 11 (the oldest version you could be using).

and reuse the port if possible.

Windows has all sorts of wonky and hard to follow rules on what socket options can be used under what conditions.
You'll probably find that there's nothing you really can do on the Java or Jetty side, as ultimately Java is just calling the OS level APIs to set the Socket options and are being rejected by those same APIs.

If you take look at C# or Dot-Net you'll find that at least those runtimes will also fail on setting SO_REUSEADDR and say something along the lines of "System.PlatformNotSupportedException: Socket options not supported on this platform, as they are invalid for use after a failed connection attempt"

@joakime
Copy link
Contributor Author

joakime commented Oct 17, 2022

ldziedziul added a commit to ldziedziul/hazelcast that referenced this issue Sep 6, 2023
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
ldziedziul added a commit to hazelcast/hazelcast that referenced this issue Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side Microsoft Windows For issues unique to Microsoft Windows
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants