Only retry UDP socket bind if it returned EADDRINUSE #1761
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the NextRandomUdpSocket picks a random port in the ephemeral
port range and attempts to bind a UDP socket to it. If that bind
operation fails, it indiscriminately retries several times before
allowing the caller to poll again, assuming that it failed because the
randomly selected port was in use.
However, this means that if
bind
fails for another reason than therequested port being unavailable, such as insufficient capabilities to
bind a socket, this error will not be propagated to the caller. Instead,
with this change, NextRandomUdpSocket immediately returns any error
returned from
bind
unless it is EADDRINUSE, in which case, it picksanother random port and tries again as before.
This was observed in a test on Fuchsia because, if the DNS resolver does not
have access to the capability required from the network stack to create and bind
sockets, it will see an
EPIPE
(broken pipe) error onbind
.