-
Notifications
You must be signed in to change notification settings - Fork 911
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
conn: Implement driver.Validator, SessionResetter for cancelation #1079
Conversation
Commit 8446d16 released in 1.10.4 changed how some cancelled query errors were returned. This has caused a lib/pq application I work on to start returning "driver: bad connection". This is because we were cancelling a query, after looking at some of the rows. This causes a "bad" connection to be returned to the connection pool. To prevent this, implement the driver.Validator and driver.SessionResetter interfaces. The database/sql/driver package recommends implementing them: "All Conn implementations should implement the following interfaces: Pinger, SessionResetter, and Validator" Add two tests for this behaviour. One of these tests passed with 1.10.3 but fails with newer versions. The other never passed, but does after this change.
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! i think this will fix the concern raised in this comment #1000 (comment)
just had a small comment
conn.go
Outdated
} | ||
|
||
func (cn *conn) IsValid() bool { | ||
// panic("TODO IsValid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Embarrassing! Thanks for noticing. Removed.
Sorry for the massive delay. I must have lost the github notification on the PR. I have merged the latest master, and have fixed the code review comment above. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution!
@evanj thanks for the fix, we ran into the same issue recently |
Commit 8446d16 released in 1.10.4 changed how some cancelled query
errors were returned. This has caused a lib/pq application I work on
to start returning "driver: bad connection". This is because we were
cancelling a query, after looking at some of the rows. This causes a
"bad" connection to be returned to the connection pool.
To prevent this, implement the driver.Validator and
driver.SessionResetter interfaces. The database/sql/driver package
recommends implementing them:
"All Conn implementations should implement the following interfaces:
Pinger, SessionResetter, and Validator"
Add two tests for this behaviour. One of these tests passed with
1.10.3 but fails with newer versions. The other never passed, but
does after this change.