lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.86k stars 908 forks source link

conn: Implement driver.Validator, SessionResetter for cancelation #1079

Closed evanj closed 1 year ago

evanj commented 2 years ago

Commit 8446d16b89 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.

jimenez commented 1 year ago

👍

evanj commented 1 year ago

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!

timbunce commented 1 year ago

@rafiss can your request for changes be removed now that @evanj addressed your concerns?

fho commented 1 year ago

@evanj thanks for the fix, we ran into the same issue recently