-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database/sql: close driver.Connector if it implements an io.Closer #41790
Comments
CC @kardianos |
The bar to expand or update the existing database/sql (v1) is fairly high However, the change is simple and won't interact with anything else. There is one other situation that this would help. If a driver for a database without inline connection cancelation has a background goroutine/connection dedicated to closing connections, this would provide a way to prevent that connection from leaking. I would say tentatively accept. |
@kardianos, we'll take care of updating the proposal project status. It needs to go through some discussion before moving to likely accept. Thanks. |
Adding to minutes. |
Does anyone object to adding this? |
Based on the discussion, this seems like a likely accept. |
No change in consensus, so accepted. |
Change https://golang.org/cl/258360 mentions this issue: |
I propose adding a new
sql.DB.Close
behavior/side effect: closingdriver.Connector
if it implements an optionalio.Closer
interface.See CL 258360 / #41710
We would like to be able to manage the resources in
driver.Connector
, e.g. to share the same underlying database handle between multiple connections. This is required for some embedded databases with in-memory backends like SQLite and Genji so that we don’t create a new in-memory store wheneversql.DB
decides to ask for a new connection by callingdriver.Connector.Connect
.For in-memory storage go-sqlite3 driver docs currently advice manually setting
cache=shared
DSN parameter, and non-zero max idle connection limit and infinite connection lifetime onsql.DB
. (see FAQ: Why I'm getting no such table error?).It get worse with Genji since both on-disk BoltDB and BadgerDB engines lock the database. That is, connector can’t open the database until the existing handle is closed. With
database/sql
it means that either user must set connection limit to 1, or we have to share the handle betweendriver.Conn
instances, which also allows us to support concurrent transactions with BadgerDB (see genjidb/genji#210).That said, we need to release the resources held by
driver.Connector
(e.g. close file handle, unlock database or free unmanaged memory) whensql.DB
is no longer needed.The text was updated successfully, but these errors were encountered: