Skip to content

Commit fb6306f

Browse files
authored
fix: resolve Goroutine leak in database connection close (apache#3491)
When a connection is opened via databaseImpl, the cache clientCache initializes *flightsql.Client objects which require proper cleanup on connection close to prevent Goroutine leaks. Previously, closing a connection released only 3 of the 6 Goroutines created per connection, leaving 3 Goroutines associated with the cached client unmanaged. This resulted in accumulated Goroutine leaks over time. The fix ensures all Goroutines are properly cleaned up when connections are closed.
1 parent 3774b82 commit fb6306f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

go/adbc/driver/flightsql/flightsql_connection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ func (c *connectionImpl) Close() error {
11311131
}
11321132
}
11331133

1134+
c.clientCache.Purge()
11341135
err = c.cl.Close()
11351136
c.cl = nil
11361137
return adbcFromFlightStatus(err, "Close")

go/adbc/driver/flightsql/flightsql_database.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,13 @@ func (d *databaseImpl) Open(ctx context.Context) (adbc.Connection, error) {
494494
if err != nil {
495495
d.Logger.Debug("failed to close client", "error", err.Error())
496496
}
497-
}).Build()
497+
}).PurgeVisitorFunc(func(_ interface{}, client interface{}) {
498+
conn := client.(*flightsql.Client)
499+
err := conn.Close()
500+
if err != nil {
501+
d.Logger.Debug("failed to close client", "error", err.Error())
502+
}
503+
}).Build()
498504

499505
var cnxnSupport support
500506

0 commit comments

Comments
 (0)