Add leak detector#811
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive goroutine leak detection using go.uber.org/goleak. It adds TestMain files to various packages, implements Close methods for resource cleanup in the responses package, and integrates leak checks into the E2E test suite. A maintainability improvement was suggested to extract duplicated leak-checking logic in e2e/e2e_test.go into a helper function.
…dedicated function
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Store.Close closes an unprotected stopCh, so multiple Close invocations (e.g., via HTTPHandler.Close and additional cleanups) will panic; consider making Close idempotent with a sync.Once or a non-blocking select pattern.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Store.Close closes an unprotected stopCh, so multiple Close invocations (e.g., via HTTPHandler.Close and additional cleanups) will panic; consider making Close idempotent with a sync.Once or a non-blocking select pattern.
## Individual Comments
### Comment 1
<location path="pkg/responses/store.go" line_range="41-42" />
<code_context>
+// Close stops the background cleanup goroutine. It must be called when the
+// Store is no longer needed to avoid a goroutine leak.
+func (s *Store) Close() {
+ close(s.stopCh)
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Make Store.Close idempotent to avoid panics on multiple calls or shared use
Calling Close more than once on the same Store will panic due to closing an already-closed channel, which is likely if the Store is shared or shutdown is triggered multiple times (e.g., in tests or signal handlers). Please make Close idempotent (e.g., via sync.Once or an atomic flag) and have cleanupLoop listen on a read-only done channel so repeated Close calls are safe and don’t crash the process.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| func (s *Store) Close() { | ||
| close(s.stopCh) |
There was a problem hiding this comment.
issue (bug_risk): Make Store.Close idempotent to avoid panics on multiple calls or shared use
Calling Close more than once on the same Store will panic due to closing an already-closed channel, which is likely if the Store is shared or shutdown is triggered multiple times (e.g., in tests or signal handlers). Please make Close idempotent (e.g., via sync.Once or an atomic flag) and have cleanupLoop listen on a read-only done channel so repeated Close calls are safe and don’t crash the process.
No description provided.