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

database/sql: need to reset connections based on error #71429

Closed
awangConfluent opened this issue Jan 24, 2025 · 2 comments
Closed

database/sql: need to reset connections based on error #71429

awangConfluent opened this issue Jan 24, 2025 · 2 comments
Labels
Question Issues that are questions about using Go.

Comments

@awangConfluent
Copy link

Background

We received an error ERROR: cache lookup failed for type 16488 (SQLSTATE XX000) upon making a db query. The root cause of the error is because the service had a stale connection to a database and service owners had run a migration on the DB.
In the old pod, it was still making queries with that stale connection, there was a type consistency issue where the connection didn’t know of the new type created by the migration. But in the new pod, everything was fine. The issue gets resolved once the service owner restarted the pods and the connections got reset.

Question

Now *sql.driverConn.validateConnection() marks a connection "needReset" (after calling *driverConn.releaseConn()) and *sql.driverConn.putConn() puts the connection to the current connection pool. The connection is reset when it's picked from the pool with “needReset” marker. My understanding is that we can't get a reset connection until all connections in the pool are marked "needReset".

My question is how can we reset the connection manually when we feel it's necessary? Or any advice for this case? Thank you!

@cyrusv
Copy link

cyrusv commented Jan 24, 2025

Thanks, this makes sense! It would be even nicer if, upon cache lookup failure, we reset the connection and try again. Perhaps this needs to be done at application layer, but would be very convenient for a lot of cases if it could be done in the library.

@seankhliao seankhliao changed the title go/src/database/sql: need to reset connections based on error database/sql: need to reset connections based on error Jan 24, 2025
@seankhliao
Copy link
Member

https://pkg.go.dev/database/sql#Conn.Raw

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
@gabyhelp gabyhelp added the Question Issues that are questions about using Go. label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Issues that are questions about using Go.
Projects
None yet
Development

No branches or pull requests

4 participants