SAP / go-hdb

SAP HANA Database Client for Go
Apache License 2.0
168 stars 57 forks source link

goroutine leak detected in the driver package: callConverter #130

Closed crobert-1 closed 9 months ago

crobert-1 commented 9 months ago

Context Hello, I'm currently working on https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30438 to enable goleak to check for leaked goroutines.

Bug Here's the stack trace for the leaked goroutine:

[Goroutine 9 in state select, with database/sql.(*DB).connectionOpener on top of the stack:
database/sql.(*DB).connectionOpener(0xc002123d40, {0x10895f940, 0xc002209770})
        /usr/local/Cellar/go/1.21.0/libexec/src/database/sql/sql.go:1218 +0x87
created by database/sql.OpenDB in goroutine 1
        /usr/local/Cellar/go/1.21.0/libexec/src/database/sql/sql.go:791 +0x165

I used a debugger to find the source of the leaking goroutine which is the following line: https://github.com/SAP/go-hdb/blob/36ea7b41334b479b3878d3ae77ae89ed1cf9a979/driver/callconverter.go#L22

This line is executed when any package simply imports "github.com/SAP/go-hdb/driver". sql.OpenDB starts a goroutine to open the connection. There's currently no way to properly close the SQL DB connection as callConverter is a private variable.

Suggested solution The best solution here would be a lazy instantiation, to only open the SQL DB connection when required. Also, the package should handle closing the connection on Close.

stfnmllr commented 9 months ago

should be fixed with https://github.com/SAP/go-hdb/releases/tag/v1.7.5