Skip to content

Add leak detector#811

Merged
ilopezluna merged 4 commits into
mainfrom
add-leak-detector
Mar 30, 2026
Merged

Add leak detector#811
ilopezluna merged 4 commits into
mainfrom
add-leak-detector

Conversation

@ilopezluna
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread e2e/e2e_test.go Outdated
@ilopezluna ilopezluna marked this pull request as ready for review March 30, 2026 13:32
@ilopezluna ilopezluna changed the title [WIP] Add leak detector Add leak detector Mar 30, 2026
@ilopezluna ilopezluna merged commit 183e38c into main Mar 30, 2026
16 checks passed
@ilopezluna ilopezluna deleted the add-leak-detector branch March 30, 2026 13:32
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread pkg/responses/store.go
Comment on lines +41 to +42
func (s *Store) Close() {
close(s.stopCh)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

2 participants