Skip to content

Conversation

@dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Feb 6, 2026

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.

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.
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

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

@n0bot n0bot bot added this to iroh Feb 6, 2026
@github-project-automation github-project-automation bot moved this to 🚑 Needs Triage in iroh Feb 6, 2026
Copy link
Contributor

@Arqu Arqu left a comment

Choose a reason for hiding this comment

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

Looks very reasonable but I have 0 clue about the blast radius of it.

Copy link
Contributor

@flub flub left a comment

Choose a reason for hiding this comment

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

I'd love a description though, why are you looking at this? what were the symptoms? what was the bug?

@dignifiedquire dignifiedquire changed the title fix(netwatch): improve rebind fix(netwatch): improve UDP rebind Feb 6, 2026
@dignifiedquire dignifiedquire merged commit 17ef4e3 into main Feb 6, 2026
25 of 29 checks passed
@dignifiedquire
Copy link
Contributor Author

I'd love a description though, why are you looking at this? what were the symptoms? what was the bug?

done

@github-project-automation github-project-automation bot moved this from 🚑 Needs Triage to ✅ Done in iroh Feb 6, 2026
@dignifiedquire dignifiedquire deleted the fix-rebind branch February 6, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants