Conversation
Core issues causing connection hangs and ip cooldown errors: 1. No write mutex on shared source TCP connections in centralserver: concurrent WriteFrame calls from different ConnIDs interleaved bytes, corrupting the frame stream. Added sourceConn wrapper with writeMu. 2. Reorderer had no gap-skip mechanism: a single lost frame permanently stalled the connection. Added 2s gap timeout — skips to lowest buffered seq after grace period expires. 3. readLoop silently dropped frames when channel buffer (256) was full, causing reorderer stalls. Replaced with 5s backpressure timeout + log. 4. SOCKS5 bind address was drained before checking REP field: on upstream CONNECT failure the server may close immediately, causing a hang on the drain ReadFull. Now checks REP first, drains only on success. 5. handleFIN did not call removeConn, leaving connState orphaned in the map until the 30s cleanup loop ran. Fixed to remove immediately. 6. Hardcoded 5-minute max connection lifetime killed long downloads and video streams. Removed — cleanup now only on actually broken state. 7. ConnIDGenerator started at 1 on every restart; if centralserver still held old state, IDs collided. Added random starting offset via NewConnIDGenerator() using crypto/rand. 8. Health probe used a fixed ConnID per instance (0xFFFF0000+instID), causing collisions when a previous probe hadn't been cleaned up yet. Now combines instance ID + monotonic counter + random byte. 9. Context cancellation in packet-split relay didn't unblock the goroutine blocked on client.Read. Added a goroutine that closes clientConn on ctx.Done so both relay directions exit promptly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.
fix: resolve packet_split instability — 9 critical bug fixes
Core issues causing connection hangs and ip cooldown errors:
No write mutex on shared source TCP connections in centralserver:
concurrent WriteFrame calls from different ConnIDs interleaved bytes,
corrupting the frame stream. Added sourceConn wrapper with writeMu.
Reorderer had no gap-skip mechanism: a single lost frame permanently
stalled the connection. Added 2s gap timeout — skips to lowest buffered
seq after grace period expires.
readLoop silently dropped frames when channel buffer (256) was full,
causing reorderer stalls. Replaced with 5s backpressure timeout + log.
SOCKS5 bind address was drained before checking REP field: on upstream
CONNECT failure the server may close immediately, causing a hang on
the drain ReadFull. Now checks REP first, drains only on success.
handleFIN did not call removeConn, leaving connState orphaned in the
map until the 30s cleanup loop ran. Fixed to remove immediately.
Hardcoded 5-minute max connection lifetime killed long downloads and
video streams. Removed — cleanup now only on actually broken state.
ConnIDGenerator started at 1 on every restart; if centralserver still
held old state, IDs collided. Added random starting offset via
NewConnIDGenerator() using crypto/rand.
Health probe used a fixed ConnID per instance (0xFFFF0000+instID),
causing collisions when a previous probe hadn't been cleaned up yet.
Now combines instance ID + monotonic counter + random byte.
Context cancellation in packet-split relay didn't unblock the goroutine
blocked on client.Read. Added a goroutine that closes clientConn on
ctx.Done so both relay directions exit promptly.