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

[3.0] Fix Failing Test due to Unwanted Port Reuse #32

Open
wants to merge 1 commit into
base: sustaining/3.x
from

Conversation

@Kortanul
Copy link
Member

Kortanul commented Apr 18, 2019

It looks like this test was failing because the kernel is reusing the same port for two different sockets within the same application (despite us not asking for this at all). In JDK 9+, we can control this via StandardSocketOptions.SO_REUSEPORT, but that option is not available in JDK 8. As a workaround, setting address reuse on the placeholder socket seems to prevent the subsequent socket from binding to the same port.

Closes #29.

It looks like this test was failing because the kernel is reusing the same port for two different sockets within the same application (despite us not asking for this at all). In JDK 9+, we can control this via `StandardSocketOptions.SO_REUSEPORT`, but that option is not available in JDK 8. As a workaround, setting address reuse on the placeholder socket seems to prevent the subsequent socket from binding to the same port.
@Kortanul Kortanul force-pushed the Kortanul:feature/3.0/issue-29--port-reuse-test-fix branch from ff8d4a5 to 9e5a6fa Apr 18, 2019
@Kortanul Kortanul changed the title [#29] Fix Failing Test due to Unwanted Port Reuse [3.0] Fix Failing Test due to Unwanted Port Reuse Apr 18, 2019
Copy link
Member

siepkes left a comment

LGTM in the sense that getting the actual port number of a free port without binding the port so you can later bind the port is always messy (it's prone to race conditions since the port isn't actually reserved).

Ideally you should just instantiated the ServerSocket in such a way that the kernel will bound a free port. Like this new ServerSocket(0). Especially in in test cases that can save you a lot of headaches. Problem is that this is not always possible since some API simply only expects a port number on which it starts listening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.