database/sql: goroutine leak detection made difficult with sql.DB.Close() #50616
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
We start a goroutine for connectionOpener like this:
go/src/database/sql/sql.go
Line 794 in 4f0c32d
And then it terminates when the context is cancelled:
go/src/database/sql/sql.go
Lines 1224 to 1233 in 4f0c32d
Which happens here:
go/src/database/sql/sql.go
Line 910 in 4f0c32d
The Close() method then returns after some additional cleanup. Since we don't wait for the actual goroutine to close, after Close() happens, there could still be a goroutine running.
I think we should add something like this to the
OpenDB
method:and then add this to the
Close()
method:This would make it easier to use things like goleak with this library. Currently, I have to workaround it somehow, e.g. with a sleep or an ignore.
The text was updated successfully, but these errors were encountered: