HTTP exporter driver leaks one connection, 3 goroutines and ~27 KB heap per push #2006
Unanswered
imtiazmangerah
asked this question in
Ledger Architecture
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Component:
internal/replication/drivers/http/driver.go,Driver.AcceptVersions:
main(99c372e3f) and v2.4.12; the file is identical onrelease/v2.4.Symptom
A long-running
ledger workerwith an HTTP exporter grows open sockets, goroutines and heaplinearly with the number of pushes until it is restarted.
Cause
Acceptcallsc.httpClient.Do(req)and never reads or closesrsp.Body. The keep-aliveconnection is never returned to the transport, so every push dials a new connection and the
previous one stays alive with its read/write goroutines and buffers.
Reproduction
Needs only Go (the
go.modtoolchain, go1.25) and network access for the clone. No Postgres,no running ledger. Every command below was run as written against a fresh clone.
mainConnection and goroutine counts are exact; the heap delta varies by a few hundred KB between runs.
fix.diffFix
Drain and close the body after
Do, as infix.diff. PR with this change and a regression test:formancehq/ledger#1905. The test,
TestHTTPDriverReusesConnections, requires 20 pushes to open oneconnection; it fails on
main(20) and passes with the fix.Disclosure
Triaged with Claude Fable 5.1 (Anthropic, model id
claude-fable-5-1, via Claude Code). Thefinding comes from our production export worker needing periodic restarts. Every number above and
the fix were reproduced by running the listed commands, and the findings, numbers and fix were
reviewed and verified by the author.
All reactions