lib / pq

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

issue 1062: Keep track of (context cancelled) error on connection, and make rows.Next return it #1064

Closed mjl- closed 2 years ago

mjl- commented 2 years ago

For https://github.com/lib/pq/issues/1062

Instead of just whether the connection is ErrBadConn. Often times, the error will still be ErrBadConn. But for expired/cancelled contexts, it will be the error for the context. Most functions still return ErrBadConn per the database/sql/driver contract ("ErrBadConn should only be returned from [...] a query method"). For rows.Next() we return the context-related error.

The database/sql/driver contract doesn't look very precise. Is Next a "query method" and should database/sql handle ErrBadConns when Next returns them?

Do we have more functions that should return the canceled-context error message?

otan commented 2 years ago

looks like this is also failing tests

mjl- commented 2 years ago

The failed error was due to existing checks around "context canceled" not handling the error. Those places still check for driver.ErrBadConn. I'll look into if I can remove those errors there.

I'll also look into your other cleanup suggestions. Hopefully within the next few days.