fix(shared): clean up zero-count entries in ConnectionLimiter to prevent memory leak - #3449
fix(shared): clean up zero-count entries in ConnectionLimiter to prevent memory leak#3449chill-czar wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 119faf42c5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
e4f15b5 to
350f31f
Compare
|
Hi @jakubno @ben-fornefeld , would appreciate a review on this when you have a moment. Quick summary: Addresses a memory leak in |
Closes #3448
Summary
ConnectionLimitermap when all active connections for a key are released.RemoveCbinRelease(key)withinpackages/shared/pkg/connlimit/limiter.go.packages/shared/pkg/connlimit/limiter_test.goasserting zero-count map key cleanup and fresh re-acquisition behavior.Why
ConnectionLimiterinpackages/shared/pkg/connlimittracks per-key concurrent connections in ansmap.Map[*atomic.Int64]. Previously,Release(key)decremented the counter to0viaCompareAndSwap, but never removed the key entry from the underlying concurrent map.For generic HTTP proxy connection limiting and client-IP rate limiting where there is no sandbox termination event to invoke
Remove(key)manually, every historic unique key remained in memory with count0. On long-running edge proxy services (client-proxyandorchestrator/pkg/tcpfirewall), this resulted in steady heap memory accumulation over time.smap.RemoveCbchecksv.Load() == 0undersmap's internal shard lock, guaranteeing zero-count keys are safely removed without race conditions against concurrentTryAcquirecalls.Test Plan
go test -race -v ./packages/shared/pkg/connlimit/...limiter.connections.Count(). assertions-race)go fmt ./...packages/sharedtest suite/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi