Hi, thanks for your response. My reply is inline below. On Saturday, 8 November 2025 at 10:18:12 UTC+13 robert engels wrote:
I looked through the code some more, and I think these lines are where the connector should close/wait for outstanding connections to be finished. https://github.com/golang/go/blob/d36e88f21f56dcf45fed2231fe28f948a31c936b/src/database/sql/sql.go#L951C1-L956C3 I would assume this is the connector’s responsibility as long as it implements io.Closer. I have’t run anything through we I could break point and see what’s going on. I look through the other structures and it certainly seems like closing and waiting (for statements on each connection to be done) is a responsibility. I agree that the connector _could_ keep track of connections and then block waiting for them to be closed in its Close method, and that this would cause the DB.Close method to block and wait for all the connections to be returned to the pool and thus be closed. But, I can't find a single example of a connector that actually does that. In the standard library, we have database/sql.dsnConnector, which is used for drivers that don't implement DriverContext. This doesn't have a Close method. The very popular pgx library also doesn't have a Close method on its connector type: https://github.com/jackc/pgx/blob/f2d5d4447821540092446e81246c0d9c27acf5cf/stdlib/sql.go#L256 No Close method in the github.com/go-sql-driver/mysql driver either: https://github.com/go-sql-driver/mysql/blob/76c00e35a8d48f8f70f0e7dffe584692bd3fa612/connector.go#L21 I think it's more likely that the documentation for DB.Close is misleading, and it is _not_ expected to block waiting for all connections to be closed, than every implementation of driver.Connector, including in the standard library, is missing an undocumented requirement to track and wait for connection in their optional Close method. Or have I misunderstood your point? Cheers, Toby. But the stblib test case would fail if there were open connections are the close, based on these: https://github.com/golang/go/blob/5cd1b73772e339e3b460d53ba37630704a323ca7/src/database/sql/sql_test.go#L176C2-L182C3 -- 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/b09ff43a-0713-4b88-bbc4-374c63f1f828n%40googlegroups.com.
