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

Add serverSocket.setReuseAddress(true); #91

Merged
merged 3 commits into from
Feb 13, 2023

Conversation

jonathanjonathan001
Copy link
Contributor

@safstromo - could you check on your Linux system that this works?

Fixes #90

safstromo
safstromo previously approved these changes Feb 13, 2023
Copy link
Contributor

@safstromo safstromo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work for me! 👍

Copy link
Contributor

@kappsegla kappsegla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After careful reading of ServerSocket documentation I think that the setReuseAddress(true) has to be set before binding the socket. Therefor we can't use the constructor that automatically binds to a port, because then it's too late to change SO_REUSEADDR.
A better implementation that should work might be:
try (ServerSocket socket = new ServerSocket()) { socket.setReuseAddress(true); socket.bind(new InetSocketAddress(6379));

This changes the status of reuse address before binding happens.

@sonarcloud
Copy link

sonarcloud bot commented Feb 13, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@kappsegla kappsegla added this pull request to the merge queue Feb 13, 2023
Merged via the queue into main with commit db39746 Feb 13, 2023
@kappsegla kappsegla deleted the 90-add-socket-reuse-address-true branch February 14, 2023 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add socket.setReuseAddress(true); for avoiding issues with the server in waiting mode
3 participants