Repository navigation
fix: release per-connection dump goroutines by closing pipe writers - #177
xianyu-sheng wants to merge 1 commit into
Conversation
handleClientMessage and handleServerMessage create an io.Pipe and start a protocol dump goroutine reading from it, but never close the pipe writer. When the proxied connection ends the dump goroutines stay blocked on r.Read forever, leaking two goroutines per connection. Close the writer when the handler returns so the reader observes EOF. Add a regression test that opens and closes connections and asserts the goroutine count returns to the baseline.
|
Thanks for the review so far. I'm preparing a public dataset of redacted audit trajectories from SmartBench and would like to include this case. The record would contain only analysis/rule IDs, project-relative file paths and line numbers, the finding summary, and this public thread URL. It would not include raw prompts/responses, secrets, or absolute paths. Nothing is published without your explicit consent. If you're comfortable with that, please reply with: "I, , consent to SmartBench publishing a redacted audit trajectory for kevwan/tproxy under CC BY 4.0." If you'd prefer not to be included, just say so — we won't publish it and will delete our local copy. No response also means it stays unpublished. We can list the repository on the data-contributor leaderboard only if you consent; tell us if you prefer a display name or no listing. Policy: https://github.com/xianyu-sheng/SmartBench/blob/main/trajectories/CONSENT.md |
|
The goroutine leak is worth fixing, but this PR needs revision before merging: closing the writers exposes EOF handling bugs in several supported protocol dumpers.
Validation: reviewed head |
fix: release per-connection dump goroutines by closing the pipe writers
Problem
handleClientMessageandhandleServerMessageeach create anio.Pipe, handits writer to the copy path and start a protocol-dump goroutine that reads from
the pipe:
The writer is never closed. When the proxied connection ends,
copyDatareturns and
c.stop()closes both network connections, but the dump goroutinestays blocked in
r.Read(...)forever — anio.Pipereader only observes EOFwhen the writer is closed. Every proxied connection leaks two goroutines.
Reproduction
conn_test.gostarts tproxy in-process against a local echo backend, opens andcloses 5 connections, then compares
runtime.NumGoroutine()with the baseline.Before:
After closing the pipe writer when the handler returns:
go test -count=3passes.Detection
Found during a SmartBench audit of
the repository. Its evidence-gated LLM review on the vulnerable revision flags
the pipe writer handling at
conn.go:64-82and recommendsdefer w.Close();the reproduction above confirms the finding independently of the audit.
Thanks!