-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: Cleanup ResourcePool & Include Mutex Lock for refreshPool
#19001
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
Signed-off-by: Max Qian <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
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.
Pull request overview
This PR addresses resource leakage and data race issues in the resource pool tests and implementation. The primary goal is to fix flaky tests in resource_pool_test.go by ensuring proper cleanup of resource pools and adding thread-safe access to the refresh ticker mechanism.
Key Changes
- Added proper cleanup (
Close()calls) toTestShrinkingandTestReopento prevent resource leaks between tests - Introduced mutex synchronization (
sync.Mutex) inpoolRefreshto fix data races when accessingrefreshTickerand related fields - Removed unused
resetCountatomic variable from test file
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| go/pools/resource_pool_test.go | Added defer p.Close() in TestShrinking and p.Close() in TestReopen to prevent resource leaks; removed unused resetCount variable |
| go/pools/refresh_pool.go | Added mutex to protect concurrent access to refreshTicker, refreshStop, and goroutine lifecycle in startRefreshTicker() and stop() methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| pr.mu.Lock() | ||
| defer pr.mu.Unlock() | ||
|
|
Copilot
AI
Dec 7, 2025
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.
The startRefreshTicker() method doesn't check if a ticker is already running before creating a new one. This can lead to resource leaks (goroutines and tickers not being cleaned up) if startRefreshTicker() is called multiple times. Consider adding a check after acquiring the lock:
pr.mu.Lock()
defer pr.mu.Unlock()
if pr.refreshTicker != nil {
return // ticker already running
}
pr.refreshTicker = time.NewTicker(pr.refreshInterval)
...| if pr.refreshTicker != nil { | |
| return // ticker already running | |
| } |
Description
This PR cleans up the resource leakage from
TestReopenandTestShrink, which causes flaky tests across ./go/pools/resource_pool_test.go. During my local run,TestIdleTimeoutended up failing withProperly closing the resource pool helped to resolve the first issue but surfaces data race from refreshPool:
Thus, a mutex lock for refreshPool.go is included here as well.
Related Issue(s)
related to #18965
Checklist
Deployment Notes
AI Disclosure
This PR was written with the help of Claude Sonnet 4.5