-
Notifications
You must be signed in to change notification settings - Fork 853
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
Faster shutdown of pgxpool.Pool background goroutines #1642
base: master
Are you sure you want to change the base?
Conversation
ticker := time.NewTicker(500 * time.Millisecond) | ||
defer ticker.Stop() |
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.
I opted for a time.Ticker
on this one for simplicity, but this does have the side effect of changing this behavior from a "sleep 500ms between attempts" to a "make an attempt every 500ms" type behavior. If the health checks take awhile then there could be minimal sleeping time.
I can refactor to use a timer, it would just be messier. I wanted to propose this option first and see what you think.
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.
I don't actually understand the purpose of this change. Aside from the wait 500ms between vs try every 500ms it doesn't change anything does it?
I took a fresh look at this, and I wonder if And if we wanted to be super rigorous, instead of calling |
When a pool is closed, some background goroutines may be left open, particularly for health checks as detailed in jackc#1641. Two specific examples have been refactored here to avoid a blocking sleep and instead also select on the pool being closed to potentially return/continue sooner.
d2d8635
to
749542e
Compare
@jackc Just pushed an updated version, is this roughly what you had in mind? Note that I needed to introduce a mutex for synchronization over the new timer field. I considered instead just setting this field up as part of pool init so it never needs to be directly written to, but if I did that I would need to specify an initial duration for the timer. Always triggering a health check 500ms after startup seems like a behavioral change AFAICT so I didn't want to go down that route without discussing. |
I think it would be fine to initially set the timer to 100 years or something like that. Then |
I realized a cleaner way to do this is to call One "hack" would be in the destructor passed to puddle to do: go func() {
p.p.Stat()
select {
case p.healthCheckChan <- struct{}{}:
default:
}
}() The reason this works is that That's obviously relying on something that puddle isn't guaranteed to maintain but maybe it'll inspire some better ideas. |
any update? |
When a pool is closed, some background goroutines may be left open, particularly for health checks as detailed in #1641. Two specific examples have been refactored here to avoid a blocking sleep and instead also select on the pool being closed to potentially return/continue sooner.