Python handlers abandoned past their deadline keep running and accumulate

オープン
#697 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
43/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, python, rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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().

主要言語
Rust
スター
37
フォーク
8
平均マージ
14時間 16分
マージ済み PR(30日)
244

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hardbyte/awa のほかの issue

hardbyte/awa の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。