On Thursday, 6 November 2025 at 18:14:06 UTC+13 Robert Engels wrote:


Isn’t the design supposed to be that the driver maintains the connections 
so when you close the db, it closes the driver connection, and that should 
wait until the current statements complete or terminate them. Terminating a 
live connection is going to be db specific.

I think it is driver issue. 


As far as I can tell, the only indication the driver gets that the DB has 
been closed is the following code:

if c, ok := db.connector.(io.Closer); ok {
    err1 := c.Close()
    if err1 != nil {
        err = err1
    }
}

Are you saying that the connector (which implements 
database/sql/driver.Connector) is expected to keep track of open 
connections and block in its Close method for them to be closed? Or to 
actively terminate them?

The doc for the Connector interface does mention DB.Close, but doesn't 
really say what it's expected to do:

// A Connector represents a driver in a fixed configuration
// and can create any number of equivalent Conns for use
// by multiple goroutines.
//
// A Connector can be passed to [database/sql.OpenDB], to allow drivers
// to implement their own [database/sql.DB] constructors, or returned by
// [DriverContext]'s OpenConnector method, to allow drivers
// access to context and to avoid repeated parsing of driver
// configuration.
//
// If a Connector implements [io.Closer], the [database/sql.DB.Close]
// method will call the Close method and return error (if any).

A very quick look at mysql and postgresql drivers doesn't turn up anything 
like that in their Connector implementations.

Cheers,
Toby.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/0f412c1e-b0a3-4764-80d6-5b9ee288a506n%40googlegroups.com.

Reply via email to