MagicStack / MagicStack/asyncpg
A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 8.1k
- Forks
- 468
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
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
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo fluxo relatado de pool.acquire, prepared-statement, transação explícita, cursor e async_timeout, concentrando-se no cancelamento durante as operações mostradas. Compare o comportamento com asyncio e uvloop usando as versões do PostgreSQL listadas e use o log que ocorre somente em produção como o sintoma a ser explicado. Está concluído quando o raro reset for reproduzido ou quando uma causa e uma resolução confirmadas forem estabelecidas.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- postgresql, python
- Domínio
- databases
- Tipo de issue
- Bug
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100