MagicStack / MagicStack/asyncpg

ConnectionDoesNotExistError when releasing

Offen
#624 0 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
8.1k
Forks
469
Ø Merge
18 Min.
Gemergte PRs (30 T.)
4

Beschreibung

  • asyncpg version: 0.21.0
  • PostgreSQL version: 10.7
  • Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
    the issue with a local PostgreSQL install?
    : no
  • Python version: 3.7
  • Platform: debian (docker image python:3.7.9-slim)
  • Do you use pgbouncer?: no
  • Did you install asyncpg with pip?: yes
  • If you built asyncpg locally, which version of Cython did you use?: no
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : only tried asyncio

I've found the following exception in our logs:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 214, in release
    self._con.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'

During handling of the above exception, another exception occurred:
File "/usr/local/lib/python3.7/site-packages/my_code_calling_release.py", line 40, in acquire
     await self.pool.release(con)
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 654, in release
     return await asyncio.shield(ch.release(timeout))   
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 216, in release
     raise ex   
File "/usr/local/lib/python3.7/site-packages/asyncpg/pool.py", line 206, in release
     await self._con.reset(timeout=budget)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 1137, in reset
     await self.execute(reset_query, timeout=timeout)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 295, in execute
     return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 316, in query

From what I can see, the call at self._con.reset is raising a ConnectionDoesNotExistError.
Should the exception be reraised at line 218 if the exception is an ConnectionDoesNotExistError (we know it's already closed)? It shouldn't even try to self._con.terminate() because self._con is already None (see the exception).

Not sure if the comments in that code still apply for that type of exception

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Lies den Release-Pfad rund um die Zeilen 206–218 von asyncpg/pool.py sowie den Reset-Pfad in asyncpg/connection.py und konzentriere dich darauf, wie ConnectionDoesNotExistError self._con als None zurücklässt. Reproduziere einen Regressionsfall für das Freigeben einer bereits geschlossenen Verbindung oder füge einen solchen hinzu. Überprüfe anschließend, dass release nicht versucht, eine fehlende Verbindung zu beenden, und das beabsichtigte Ausnahmeverhalten beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
postgresql, python
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.