feat(server): IPv6 dual-stack and SO_REUSEADDR for run()#1187
Open
Greg Lamberson (glamberson) wants to merge 2 commits intoDevolutions:masterfrom
Open
feat(server): IPv6 dual-stack and SO_REUSEADDR for run()#1187Greg Lamberson (glamberson) wants to merge 2 commits intoDevolutions:masterfrom
Greg Lamberson (glamberson) wants to merge 2 commits intoDevolutions:masterfrom
Conversation
Replace TcpListener::bind() with TcpSocket for control over socket options before binding: - SO_REUSEADDR: prevents EADDRINUSE on server restart (TIME_WAIT) - IPv6 dual-stack: when bound to [::], accepts both IPv4 and IPv6 on a single socket. Address family is detected from SocketAddr. - Backlog increased from default to 1024
1ed889d to
dda8242
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the RDP server’s run() listener setup to use tokio::net::TcpSocket so socket options can be set prior to binding, aiming to improve restart behavior and support IPv6 dual-stack binding.
Changes:
- Replace
TcpListener::bind()withTcpSocketto configure socket options beforebind(). - Enable
SO_REUSEADDRto reduceEADDRINUSElikelihood on restart. - Increase listen backlog to 1024.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace TcpListener::bind() with TcpSocket for control over socket options before binding: SO_REUSEADDR (unix-only): Prevents EADDRINUSE on server restart. Gated behind cfg(unix) because Windows SO_REUSEADDR has different semantics that allow port hijacking. IPv6 dual-stack: Detects address family from configured SocketAddr. When IPv6, documents platform-specific IPV6_V6ONLY behavior (Linux defaults to dual-stack, Windows/BSDs may not). Backlog: Extracted to LISTENER_BACKLOG constant (1024). No new dependencies. Backward compatible.
bdf27cd to
bb4e31b
Compare
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.
Replace
TcpListener::bind()withTcpSocketfor control over socketoptions before binding:
SO_REUSEADDR: Prevents
EADDRINUSEon server restart. The previousTcpListener::bind()doesn't set this, so the port stays inTIME_WAITfor ~60 seconds after shutdown.
IPv6 dual-stack: Detects address family from the configured
SocketAddr. When IPv6 (e.g.[::]:3389), creates a v6 socket thataccepts both IPv4 and IPv6 via dual-stack (Linux default
bindv6only=0). When IPv4, usesnew_v4()as before.Backlog: Increased from the
TcpListenerdefault to 1024.No new dependencies. Backward compatible.