MagicStack / MagicStack/asyncpg
Query Wait Timout Error from Pgbouncer Not Propogating to Client
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 8.1k
- Forks
- 468
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
When pgbouncer kills a connection due to its query_wait_timeout, the error message is not propagated to the client. All that is provided to the client is a not very helpful message "connection was closed in the middle of operation". This error message seems to be correctly handled by psql and psycopg.
I replicated this by using a pgbouncer instance with a pool_size of 1 and made sure another connection was consuming this connection to ensure that the connection would be put in a waiting mode.
asyncpg version
```
> python -c 'import asyncpg; print(asyncpg.__version__)'
0.31.0
```
Example asyncpg code
```python
import asyncio
import asyncpg
async def main():
conn = await asyncpg.connect('postgresql://postgres@localhost:6432/postgres')
row = await conn.execute('SELECT 1')
asyncio.run(main())
```
Stdout from the above code
```
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "", line 3, in main
File "/path/to/venv/lib/python3.12/site-packages/asyncpg/connection.py", line 349, in execute
result = await self._protocol.query(query, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "asyncpg/protocol/protocol.pyx", line 375, in query
asyncpg.exceptions.ConnectionDoesNotExistError: connection was closed in the middle of operation
```
Example code for psycopg
```
import psycopg
with psycopg.connect("postgresql://postgres:@localhost:6432/postgres") as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
```
example traceback from psycopg
```
Traceback (most recent call last):
File "", line 3, in
File "/path/to/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
raise ex.with_traceback(None)
psycopg.errors.ProtocolViolation: query_wait_timeout
```
Example call and stdout from psql on query_wait_timeout
```bash
> psql \
'postgresql://postgres:@localhost:6432/postgres' \
--command='SELECT 1'
FATAL: query_wait_timeout
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduzieren Sie das Timeout über das im Issue beschriebene pgbouncer-Setup und beginnen Sie dann beim Connection.execute-Pfad in asyncpg/connection.py und bei query in asyncpg/protocol/protocol.pyx. Vergleichen Sie die Fehlerbehandlung mit den psycopg- und psql-Beispielen und überprüfen Sie, dass der Client den Fehler query_wait_timeout offenlegt, statt nur eine geschlossene Verbindung zu melden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, python
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100