Skip to content

Commit

Permalink
issue 1062: Keep track of (context cancelled) error on connection, an…
Browse files Browse the repository at this point in the history
…d make rows.Next return it (#1064)

* add reproducer for issue 1062

see #1062

* Keep track of an error for a connection.

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?

* in test for QueryRowContext, fail for all unexpected errors, not just for the one unexpected error

* in TestContextCancel*, accept context.Canceled as valid error

* explicitly test for driver.ErrBadConn in test that breaks the connection

feedback from otan

* move the mutex-protected data in a struct with the mutex, and fix an unsafe usage.

there may be unsafeness in this file.

feedback from otan
  • Loading branch information
mjl- authored Nov 8, 2021
1 parent 6a102c0 commit 8446d16
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 130 deletions.
Loading

0 comments on commit 8446d16

Please sign in to comment.