[3.3] Enable server socket reuseAddress option before binding#15239
[3.3] Enable server socket reuseAddress option before binding#15239AlbumenJ merged 1 commit intoapache:3.3from
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.
Are there any systems which cannot support such configuration or will throw exception here?
There was a problem hiding this comment.
if an error occurs, or the socket is closed, SocketException will be thrown here.
There was a problem hiding this comment.
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.
| } catch (IOException e) { | |
| } catch (Throwable ignore) { |
8b08a99 to
e15ba4d
Compare
e15ba4d to
cba2c7b
Compare
|
@AlbumenJ PTAL |


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