Skip to content

fix: clean worker shutdown on transport close - #47

Merged
crazydi4mond merged 1 commit into
mainfrom
fix/clean-worker-shutdown
Mar 29, 2026
Merged

crazydi4mond merged 1 commit into
mainfrom
fix/clean-worker-shutdown

Conversation

@crazydi4mond

Copy link
Copy Markdown
Contributor

Summary

Expose QueuePacketConn.Closed() channel and make all transport worker goroutines check it on each iteration, so they exit cleanly when the conn is closed during reconnect.

  • UDP sendLoop: replace for range with select on closed/outgoing, make backoff waits interruptible
  • DNS sendLoop: cache channels, add closed checks in select branches and after rateLimiter.Wait(), add defer pollTimer.Stop()
  • DNS goroutine wrappers: skip error logging on intentional close
  • HTTP/TLS sendLoop: replace for range with select on closed/outgoing

Without this fix, each reconnect cycle leaks ~100+ goroutines (UDP workers + DNS/HTTP/TLS sendLoops) that block forever on OutgoingQueue channels not closed by Close().

Partially based on ideas from #41.

Test plan

  • go build ./... / go test ./...
  • bash e2e/tunnel/run.sh txt
  • bash e2e/recovery/run.sh
  • bash e2e/transport-recovery/run.sh

Expose QueuePacketConn.Closed() channel and make all transport worker
goroutines (UDP, DNS, HTTP, TLS) check it instead of blocking forever
on OutgoingQueue channels that are never closed by Close().

Prevents ~100+ goroutine leaks per reconnect cycle.

Co-Authored-By: ebpfx <262974424+ebpfx@users.noreply.github.com>
@crazydi4mond
crazydi4mond merged commit 13c9317 into main Mar 29, 2026
20 checks passed
This was referenced Mar 29, 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.

1 participant