MagicStack / MagicStack/asyncpg
A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 8.1k
- Forks
- 468
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Sometimes our production component logs the following error
21:05:49.897964000 [Error ] [asyncio] Resetting connection with an active transaction <asyncpg.connection.Connection object at 0x7fb1502561f8>
We create a connection pool first.
Then we use async_timeout, prepared statements, explicit transaction and a cursor to get data.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.
We use a connection pool.
Later, in a different coroutine, we use async_timeout, prepared statements, explicit transaction and a cursor.
A coroutine that has this logic may be cancelled sometimes, and this is when we may see the error above. However not every
cancellation produces the error. Cancellation happens oftens but we see this error extremely rarely. I wasn't able to build a
minimal example to reproduce it.
`
pool = await asyncpg.create_pool(...)
async with async_timeout.timeout(global_delay_sec) as cm:
async with pool.acquire() as conn:
stmt = await conn.prepare(sql)
columns = stmt.get_attributes()
...
async with conn.transaction():
cursor = await stmt.cursor()
raw_values = await cursor.fetch(max_rows + 1)
if len(raw_values) == max_rows + 1:
raise Exception(f"A total number of rows exceeded the allowed maximum of {max_rows} rows")
`
-
asyncpg version:
0.20.1 -
PostgreSQL version:
Reproduced with both postgres-11 and 12 -
Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?:
No we don't use PostgreSQL SaaS
I wasn't able to reproce it the issue locally. -
Python version:
3.6.3 -
Platform:
lsb_release -d
Description: CentOS Linux release 7.6.1810 (Core) -
Do you use pgbouncer?:
no -
Did you install asyncpg with pip?:
yes -
If you built asyncpg locally, which version of Cython did you use?:
We do not build it locally -
Can the issue be reproduced under both asyncio and
uvloop?:
I do use uvloop, I couldn't reproduce it locally. It seems to be an extremely rare issue, happens in our production only once in a month
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le flux signalé de pool.acquire, prepared-statement, transaction explicite, curseur et async_timeout, en vous concentrant sur l’annulation pendant les opérations montrées. Comparez le comportement avec asyncio et uvloop en utilisant les versions de PostgreSQL indiquées, et utilisez le log qui n’apparaît qu’en production comme symptôme à expliquer. Le travail est terminé lorsque le rare reset est reproduit ou qu’une cause et une résolution confirmées sont établies.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- postgresql, python
- Domaine
- databases
- Type d'issue
- Bug
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100