-
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: add lastUseTime
or similar to driverConn, add SetConnMaxIdleLefttime to DB
#25232
Comments
lastUseTime
or similar to driverConn, add SetConnMaxIdleLefttime to DBlastUseTime
or similar to driverConn, add SetConnMaxIdleLefttime to DB
I don't fully follow what you are suggesting. However, if a driver connection sets an idle timeout in the DSN or settings then the connection will close on idle. If that connection (still in the pool) attempts to be used, it will return driver.ErrBadConn and the pool will try to pull another one. Actually, it may not be a bad idea to support a method to signal to the database connection pool that the driver is bad right away rather then retrying and risk getting all bad connections. I'm not sure how that would work of hand. |
Thanks for your prompt, I find an another way to keep conns alive by |
Sadly, I also had no idea how to achieve this feature now. But we can talk it in the future |
I think you are proposing a new database pool setting called "set max idle time" where if the connection is idle for ever the max time spent it is closed and removed from the pool. Is this correct? |
Yeah, thanks for your detailed explanation |
@kardianos, does this proposal sound good to you? OK to accept if so. |
Change https://golang.org/cl/145758 mentions this issue: |
lastUseTime
or similar to driverConn, add SetConnMaxIdleLefttime to DBlastUseTime
or similar to driverConn, add SetConnMaxIdleLefttime to DB
@leaxoy Why When I don't want to add MaxIdleTime, because it makes pool more complicated. |
Thank you for sending CL 145758 @kardianos, but unfortunately we didn't get it in for Go1.14. @methane would you mind commenting on the tagged CL about how this new method won't work for you, or how you can use the previous available methods? Thank you. |
I noticed some db like mysql support
idle timeout
, which means a conn will closed when timeout. Insql
package, only hasdb.SetConnMaxLefttime
anddriverConn.createdAt
available, so I suggest addlastUseTime
todriverConn
andSetConnMaxIdleLefttime
toDB
.The text was updated successfully, but these errors were encountered: