Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
database/sql: idle connections are not cleaned up properly #39471
What version of Go are you using (
@stevenh Thank you for taking time to test this feature. There is quite a bit of change going on here. I'm open to this or something like this but it will take me a little bit to go through this change.
We are late in the Go release cycle: https://github.com/golang/go/wiki/Go-Release-Cycle (currently the tree is frozen) so I think the soonest it could get merged would be mid-July after the Go1.15 release.
I just want to confirm the issue you are trying to address. While the max idle time does work correctly today (technically), because some amount of connections get used (picked at random), then few connections actually idle out because one of them is always picked prior to idle timeout. Your solution was to pick connection from the free list starting with the most recent return time:
There is another issue #31708 which would like to make the free list a LIFO queue.
I'll need to inspect these two issues at the same time. Again, we can work on this with the aim of getting this ready to be merged at the top of the window when it opens in July. Just don't expect it to go into the Go1.15 release.
What triggered my investigation was we saw a spike in load and connections never returned to normal levels even with our 2m
We ended up having to restart the app to bring connection limits and hence the DB memory usage back under control.
Given this I think its import to get this issue fixed before
Wanted to quickly leave a note for you that I think we hit this by accident. I had written quite inefficient code that is run very frequently. Every once in a while we'd hit a spike and used the max connections limit basically instantly making every other query fail.
Inefficient code is cleaned up and taken care of but the randomness and the instant spikes look similar to the reported issue here.
I am cross compiling the project to Linux/x86-64