MagicStack / MagicStack/asyncpg

A weird log line from the asyncio default exception handler: "Resetting connection with an active transaction"

Aperta
#652 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
8.1k
Fork
468
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il flusso segnalato di pool.acquire, prepared-statement, transazione esplicita, cursore e async_timeout, concentrandoti sulla cancellazione durante le operazioni mostrate. Confronta il comportamento con asyncio e uvloop usando le versioni di PostgreSQL elencate e usa il log che si verifica solo in produzione come sintomo da spiegare. Il lavoro è completato quando si riproduce il raro reset oppure si stabiliscono una causa e una soluzione confermate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
postgresql, python
Ambito
databases
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.