-
Notifications
You must be signed in to change notification settings - Fork 7
fix: make Close() idempotent and add Close tests #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add sync.Once to podEventLogger to ensure Close() is safe to call multiple times - Add TestCloseIdempotent to verify double-close doesn't panic - Add TestCloseDuringProcessing to verify close during active processing
Stop all active retry timers in logQueuer.cleanup() when the context is canceled. This prevents retry timers from continuing to fire after the podEventLogger is closed, which was causing integration tests to hang waiting for httptest.Server to close.
| p.closeOnce.Do(func() { | ||
| p.cancelFunc() | ||
| close(p.stopChan) | ||
| close(p.errChan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you make this wait for the goroutines to exit too? by having a defer close(p.doneChan) at the top of the work() handler?
Address review feedback: Close() now waits for the work goroutine to fully exit before returning. Added doneChan that is closed when the work loop exits, and Close() blocks on receiving from it. Also moved work goroutine startup to newPodEventLogger to ensure it's only started once (not per-namespace).
| func (l *logQueuer) work(ctx context.Context) { | ||
| func (l *logQueuer) work(ctx context.Context, done chan struct{}) { | ||
| defer l.cleanup() | ||
| defer close(done) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probs should be the first deffered handler no? defers run in LIFO order
If initNamespace fails, cancel the context and wait for the work goroutine to exit to prevent goroutine leaks.
Summary
Tests were reviewed and are reasonable overall. This PR adds missing test coverage and fixes bugs found during review.
Changes
Close()was not idempotent - calling it twice would panic due to closing already-closed channels. Addedsync.Onceto make it safe.cleanup()method to stop all retry timers when work loop exits.TestCloseIdempotent: Verifies double-close doesn't panicTestCloseDuringProcessing: Verifies close during active processing works correctlyTest Coverage Review
Well-Covered Areas ✓
Remaining Minor Gaps (not addressed in this PR)
WaitForCacheSynconly tested indirectly (acceptable)