unexpected EOF error
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 14.3k
- Forks
- 1.1k
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 11
Description
Hi 👋
First of all thank you for the amazing work here 🙌
Recently we migrate from [pq](https://github.com/lib/pq) driver to pgx and faced one issue that I would like to share with you
We started some random error in our logs that matchs with `io.ErrUnexpectedEOF` which we track down and it comes from here:
https://github.com/jackc/pgx/blob/e58381ac9409172a674f76c1801c3c606ac41b42/pgproto3/frontend.go#L210-L215
This previously was hidden from us because pq does [this](https://github.com/lib/pq/blob/d5affd5073b06f745459768de35356df2e5fd91d/error.go#L506-L511):
```go
if v == io.EOF || v.Error() == "remote error: handshake failure" {
*err = driver.ErrBadConn
} else {
*err = v
}
```
That is retried by `database/sql` (getting/opening another connection):
```go
for i := 0; i < maxBadConnRetries; i++ {
stmt, err = db.prepare(ctx, query, cachedOrNewConn)
isBadConn = errors.Is(err, driver.ErrBadConn)
if !isBadConn {
break
}
}
if isBadConn {
return db.prepare(ctx, query, alwaysNewConn)
}
```
Makes sense wrapping the `io.EOF` into a `driver.ErrBadConn` ?
This has the advantage that is out-of-the-box retried by the standard `database/sql` but maybe i'm missing another use case for that error
Another approach could be some migration guide (from pq to pgx) with a warning about this error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with pgproto3/frontend.go at lines 210-215 and compare its EOF handling with pq's error.go at lines 506-511. Review the database/sql retry behavior shown in the issue, then determine whether the outcome should be ErrBadConn handling or migration documentation; done means the chosen behavior or guidance is clearly established and covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100