fix(rendezvous): preserve peer port and handle WS heartbeat behind reverse proxy - #27
Merged
Merged
Conversation
…verse proxy Bug 1: The WS handshake callback overwrote addr with ip:0 when X-Real-IP/X-Forwarded-For was present, zeroing the peer's port. This addr was used as Peer.socket_addr, so relaying to the WS peer failed with EINVAL (os error 22) and tore down the entire UDP socket. Fix: capture forwarded_ip separately via Arc<Mutex<Option<String>>> and thread it through handle_tcp as a new parameter used only for the reported IP string, never for the routable socket_addr. Also handles X-Forwarded-For chains (takes the first/original client entry). Bug 2: The WS read loop lacked the empty-message heartbeat handling that the plain-TCP branch has. An empty RendezvousMessage parsed successfully but matched no arm in handle_tcp, returning false and closing the WS connection on the client's next keep-alive. Fix: mirror the plain-TCP heartbeat handling, handle Close frames explicitly, and log read errors instead of silently exiting the loop. Closes #26
hashbk
force-pushed
the
fix/ws-reverse-proxy-einval
branch
from
August 14, 2026 09:36
0e91fb1 to
bef15a4
Compare
YuZhiYuanDev
approved these changes
Aug 14, 2026
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.
Summary
Fixes two compounding bugs in WebSocket support that caused WSS clients behind a reverse proxy to fail ~90% of the time and experience frequent spurious disconnects.
Closes #26.
Bug 1:
X-Real-IP/X-Forwarded-Forhandling zeroes the peer's portThe WS handshake callback overwrote
addrwithip:0when a forwarded IP header was present, zeroing the peer's port. Thisaddrwas then used asPeer.socket_addr— the UDP relay destination — sosendto()to port0failed withEINVAL(os error 22), which propagated up and tore down the entire UDP listening socket, disrupting all connected clients.Fix: Capture
forwarded_ipseparately viaArc<Mutex<Option<String>>>shared into the handshake closure, and thread it throughhandle_tcpas a newforwarded_ip: Option<&str>parameter used only for the reported IP string (Peer.info.ip), never for the routablesocket_addr. Also handlesX-Forwarded-Forchains correctly (takes the first/original client entry).Bug 2: WS read loop missing heartbeat handling
The WS read loop lacked the empty-message heartbeat handling that the plain-TCP branch has. An empty
RendezvousMessageparsed successfully but matched no arm inhandle_tcp, returningfalseand closing the WS connection on the client's next keep-alive.Fix: Mirror the plain-TCP heartbeat handling (empty binary → echo empty response). Also handle
Closeframes explicitly (break immediately instead of waiting for the 30s idle timeout) and log read errors instead of silently exiting thewhile letloop.