Python handlers abandoned past their deadline keep running and accumulate

Aperta
#697 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
43/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, python, rust

Direzione di ricerca

Start by reading awa-python/src/worker.rs, especially the conversion through pyo3_async_runtimes::into_future_with_locals, and trace how the Rust executor drops the handler future on abandonment and shutdown. Reproduce with a handler that awaits forever and the issue's worker and deadline settings. Done when cancellation reaches the Python handler, live coroutines stay at or below max_workers, and no handler survives shutdown.

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

Descrizione

When a Rust runtime abandons an attempt (the handler is still running well past its deadline, after deadline + 2 × rescue interval), the executor drops the handler future, frees the worker slot and the dispatcher claims a replacement. For Python handlers that drop does not stop anything: awa-python/src/worker.rs turns the coroutine into a Rust future with pyo3_async_runtimes::into_future_with_locals, and dropping that future only drops a oneshot receiver. The asyncio task is never cancelled.

Each orphaned task keeps its Job (row and parsed args model), its coroutine frames and whatever it awaits (sockets, pooled connections). Nothing drains them, so a handler stuck on an await that never resolves (an HTTP call without a timeout, for example) leaks up to max_workers tasks per deadline-plus-grace window. If the hung await holds a pooled connection, new handlers queue on that pool and become orphans too. An orphan that wakes later can also repeat side effects for an attempt that rescue has already retried.

Reproduced with max_workers=4, deadline_duration_ms=1000 and deadline_rescue_interval_ms=200, and a handler that awaits forever: live handler coroutines grew 8 → 12 → 20 → 24 → 32 → 36 over 12 seconds, and all 36 were still running after client.shutdown().

Proposed fix: schedule the coroutine on the event loop as a task the Rust side owns (for example asyncio.run_coroutine_threadsafe, or a small helper in the Python package), and hold a drop guard that cancels it (loop.call_soon_threadsafe(task.cancel) / cancelling the concurrent future) when the Rust future is dropped, both on abandonment and on shutdown. A gauge of abandoned Python tasks still running would make the remaining cases visible.

Acceptance: with a handler that awaits forever, abandoned tasks are cancelled (the handler sees asyncio.CancelledError), the live coroutine count stays at most max_workers, and nothing survives shutdown().

Lingua principale
Rust
Stelle
37
Fork
8
Merge medio
14h 16m
PR unite (30g)
244

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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.

Altre issue di hardbyte/awa

Tutte le issue di hardbyte/awa

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.