Skip to content

Dev#20

Merged
ParsaKSH merged 3 commits intomainfrom
dev
Mar 28, 2026
Merged

Dev#20
ParsaKSH merged 3 commits intomainfrom
dev

Conversation

@ParsaKSH
Copy link
Copy Markdown
Owner

fix: resolve packet_split instability — 9 critical bug fixes

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.

ParsaKSH and others added 3 commits March 27, 2026 01:24
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>
@ParsaKSH ParsaKSH merged commit 0fd4d70 into main Mar 28, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant