Skip to content
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

proposal: database/sql: validation check db connection object before use. #50015

Closed
drakejin opened this issue Dec 7, 2021 · 3 comments
Closed

Comments

@drakejin
Copy link

drakejin commented Dec 7, 2021

from issue

go-sql-driver/mysql#1290

in my case

Network is one of unstable environment.
This project already has lots of techniques to detect and handle network problems,
however I sometimes meet unhandled network problem such as network closed without notice to driver.
In this case, developers need to check error type and decide retry or not.

proposal

So...... How about add feature pre-ping process like ping or SELECT 1+1 at JDBC(hibernates JPA), ActiveRecord(rails ORM).

For adding the above feature, I think this BeforeAcquire hook option is needed.

Adding the hook at pool config:

    BeforeAcquire   func(*Conn) error // function to call on every connection checkout to validate the connection
@gopherbot gopherbot added this to the Proposal milestone Dec 7, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Dec 8, 2021
@ianlancetaylor
Copy link
Contributor

CC @kardianos

@kardianos
Copy link
Contributor

@drakejin I understand. One change in 1.18 will allow drivers to correctly wrap errors returned from the driver. If a connection is bad, the driver can return an error that implements interface{ Is(error) bool } and if the Is driver.ErrBadConn returns true, it will discard it.

One of the challenges with a Preflight check is that it still doesn't handle issues where the connection fails between the preflight and the "real" query, so you still have to handle "real" query failures to be robust (though I understand pragmatically that doing so may reduce the number of errors in practice).

I'm would prefer not to add additional features to the existing database/sql; the current design is too brittle. I would prefer to decline this proposal.

@drakejin
Copy link
Author

@kardianos Oh~~~ driver.ErrBadConn It's such a good idea. I agree with that.

I told the feature about a BeforeAcquire option.
I think this option is more support high logical level. However, I think golang's philosophy doesn't support logically functional features. I understand that's why I like golang.

Okay. I'll ask to other project to sqlx, entd and gorm.

Have a good day :)

@seankhliao seankhliao removed this from Incoming in Proposals (old) Jul 3, 2022
@golang golang locked and limited conversation to collaborators Dec 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants