Python handlers abandoned past their deadline keep running and accumulate

Đang mở
#697 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
postgresql, python, rust

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Rust
Star
37
Fork
8
Merge trung bình
14 giờ 16 phút
Pull request đã merge (30 ngày)
244

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của hardbyte/awa

Tất cả issue của hardbyte/awa

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.