-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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.3] Enable server socket reuseAddress option before binding #15239
base: 3.3
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.3 #15239 +/- ##
============================================
- Coverage 60.79% 60.78% -0.01%
- Complexity 10892 10894 +2
============================================
Files 1885 1885
Lines 86082 86102 +20
Branches 12895 12898 +3
============================================
+ Hits 52331 52341 +10
- Misses 28303 28316 +13
+ Partials 5448 5445 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Is it possible to add some tests? |
the results of these codes vary with os and jdk version,
passed if running on win10 + compiled by jdk8, |
fd08802
to
c0ce2a7
Compare
c0ce2a7
to
d4b785c
Compare
try (ServerSocket ignored = new ServerSocket(i)) { | ||
try (ServerSocket serverSocket = new ServerSocket()) { | ||
// SO_REUSEADDR should be enabled before bind. | ||
serverSocket.setReuseAddress(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any systems which cannot support such configuration or will throw exception here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if an error occurs, or the socket is closed, SocketException will be thrown here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see. Embedded, real time system, or old Unix ( before 1980?) might not support SO_REUSEADDR. added condition check before setting it.
try (ServerSocket serverSocket = new ServerSocket()) { | ||
serverSocket.setReuseAddress(true); | ||
reuseAddressSupported = true; | ||
} catch (IOException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (IOException e) { | |
} catch (Throwable ignore) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
8b08a99
to
e15ba4d
Compare
there are still somethings need to be revised, the port |
e15ba4d
to
cba2c7b
Compare
What is the purpose of the change?
try to fix #15238
sometimes the port got from NetUtils#getAvailablePort could not be bound directly because the port status is still TIME-WAIT as getAvailablePort closed it without setting SO_REUSEADDR option.
Checklist