MagicStack / MagicStack/asyncpg
A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 8.1k
- Forks
- 468
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el flujo reportado de pool.acquire, prepared-statement, transacción explícita, cursor y async_timeout, centrándote en la cancelación durante las operaciones mostradas. Compara el comportamiento con asyncio y uvloop usando las versiones de PostgreSQL indicadas, y utiliza el log que solo aparece en producción como el síntoma que hay que explicar. Se considera terminado cuando se reproduzca el raro reset o se establezcan una causa y una resolución confirmadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- postgresql, python
- Área
- databases
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100