Skip to content

fix: close stream/resource leaks and races from full code review - #29

Merged
Gouryella merged 3 commits into
mainfrom
cursor/fix-code-review-bugs-6541
Jul 9, 2026
Merged

Gouryella merged 3 commits into
mainfrom
cursor/fix-code-review-bugs-6541

Conversation

@Gouryella

@Gouryella Gouryella commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Full code review of the drip tunneling codebase found several correctness bugs around timeouts, registration rollback, and concurrent cleanup. This PR fixes them, adds regression tests, adds a full end-to-end functional suite, and clears the CI govulncheck failure.

Fixes

  1. HTTP openStream timeout leak (internal/server/proxy/handler.go) — Unbuffered result channel caused late OpenStream completions after timeout to block forever and leak streams/goroutines. Use a buffered channel and drain/close late results on timeout.

  2. TCP proxy late-stream leak (internal/server/tcp/proxy.go) — Same pattern on timeout / stop / context cancel. Always send to a buffered channel and drain late results.

  3. Registration Get failure leak (internal/server/tcp/registration_handler.go) — If RegisterWithIP succeeded but Get failed, the port and tunnel slot were never released. Roll back with Unregister + Release(port).

  4. connQueueListener Enqueue/Close race (internal/server/tcp/http_conn_listener.go) — Enqueue could succeed after Close started, leaving connections stuck in the queue. Serialize Enqueue with Close under a mutex.

  5. WebSocket dial response body leak (internal/client/tcp/connection_dialer.go) — Close resp.Body on both success and failure paths.

  6. Heartbeat ping timeout pile-up (internal/server/tcp/connection_group.go) — Clearing pingInFlight on timeout while Ping was still running allowed overlapping Ping goroutines. Track pending completions until the real Ping finishes; late success clears the failure streak.

  7. Active connection metric underflow (internal/server/tunnel/connection.go) — Use a CAS loop so DecActiveConnections cannot go negative.

  8. CI govulncheck GO-2026-5856 — Bump Go toolchain from 1.26.4 to 1.26.5 (CI, release, Dockerfile, go.mod) to pick up the crypto/tls ECH privacy fix.

Tests

  • Unit/regression: open_stream_test.go, http_conn_listener_test.go, registration_handler_test.go
  • Full e2e: scripts/test/e2e-full.sh (make e2e) — 17/17 passed
  • GOTOOLCHAIN=go1.26.5 go run golang.org/x/vuln/cmd/govulncheck@latest ./... — no vulnerabilities found
Open in Web Open in Cursor 

cursoragent and others added 3 commits July 8, 2026 18:40
Prevent HTTP/TCP openStream timeout from leaking late streams, roll back
TCP registration when Get fails, serialize connQueueListener Enqueue with
Close, close WebSocket dial response bodies, keep heartbeat ping in-flight
until completion, and avoid active-connection metric underflow.

Co-authored-by: Gouryella <Gouryella@users.noreply.github.com>
Add scripts/test/e2e-full.sh covering HTTP/TCP over TLS and WSS, SSE
streaming, password/bearer proxy auth, concurrency, health/metrics, and
invalid token rejection. Wire it as `make e2e`.

Co-authored-by: Gouryella <Gouryella@users.noreply.github.com>
Upgrade toolchain and CI/Docker images so govulncheck no longer flags
the crypto/tls Encrypted Client Hello privacy leak fixed in go1.26.5.

Co-authored-by: Gouryella <Gouryella@users.noreply.github.com>
@Gouryella
Gouryella marked this pull request as ready for review July 9, 2026 08:41
@Gouryella
Gouryella merged commit 027a60e into main Jul 9, 2026
1 check passed
@Gouryella
Gouryella deleted the cursor/fix-code-review-bugs-6541 branch July 9, 2026 08:41
@Gouryella Gouryella mentioned this pull request Sep 7, 2026
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.

2 participants