fix(netwatch): improve UDP rebind#95
Merged
Merged
Conversation
Two fixes for socket rebinding: 1. Allow rebinding from Closed state: previously, if a rebind failed (e.g. AddrInUse), the socket was permanently stuck in Closed state and all subsequent rebind attempts would fail with 'socket is closed and cannot be rebound'. Now Closed state stores the bind address and allows retry. 2. Set SO_REUSEADDR before binding: on Wine, socket close may not be instantaneous, so rebinding to the same port immediately after dropping the old socket can fail with AddrInUse (OS error 10048). SO_REUSEADDR allows the new socket to bind even if the old one hasn't fully released the port yet.
SO_REUSEADDR on UDP sockets has security implications: it allows other processes to bind to the same port and steal packets. Instead, rely on the Closed-state recovery fix to retry rebinding on subsequent network change events.
|
Documentation for this PR has been generated and is available at: https://n0-computer.github.io/net-tools/pr/95/docs/net_tools/ Last updated: 2026-02-06T12:12:48Z |
2 tasks
Arqu
reviewed
Feb 6, 2026
Contributor
Arqu
left a comment
There was a problem hiding this comment.
Looks very reasonable but I have 0 clue about the blast radius of it.
flub
approved these changes
Feb 6, 2026
Contributor
flub
left a comment
There was a problem hiding this comment.
I'd love a description though, why are you looking at this? what were the symptoms? what was the bug?
Contributor
Author
done |
Arqu
added a commit
to n0-computer/iroh
that referenced
this pull request
Apr 7, 2026
Tests that iroh works under wine & proton in CI Depends on - [x] n0-computer/net-tools#95 - [x] n0-computer/noq#414 Ref: #3901 --------- Co-authored-by: dignifiedquire <me@dignifiedquire.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We already handle this in the drop implementation, but when doing rebind we did not properly wait for the socket to close, which caused issues on slower systems, especially wine.