jackc / jackc/pgx

Confusing error message: detected infinite loop

Open
#2,451 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

Hi, thanks for maintaining pgx! I was testing some Go code that was reliant on pgxpool with [Antithesis](https://antithesis.com/), and ran into the following error:

```
pgxpool: detected infinite loop acquiring connection; likely bug in PrepareConn or BeforeAcquire hook
```

This was confusing, because I hadn't set a PrepareConn / BeforeAcquire hook, but I went through the code and found this:

https://github.com/jackc/pgx/blob/4c1308c14b2eabaaa365e8cd69120b1de8f953e9/pgxpool/pool.go#L630-L634

It seems that in the event of a network error, if all pings to Postgres fail, pgxpool throws a `detected infinite loop` error. Could the error message here be improved somehow - and would it be possible to use a sentinel error that can be caught and handled?

Contributor guide

Open the contributing guide

Research direction

Start in pgxpool/pool.go at the linked lines 630-634 and trace the connection-acquisition path when network errors make all PostgreSQL pings fail. Check how the current infinite-loop error is produced and how callers could distinguish this condition. Done means the failure message is no longer misleading and the requested error-handling behavior is defined and covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.