Skip to content

fix(event): suppress native asyncio.QueueShutDown on Python 3.13+ - #6773

Open
axelray-dev wants to merge 3 commits into
reflex-dev:mainfrom
axelray-dev:fix/queue-shutdown-py313
Open

fix(event): suppress native asyncio.QueueShutDown on Python 3.13+#6773
axelray-dev wants to merge 3 commits into
reflex-dev:mainfrom
axelray-dev:fix/queue-shutdown-py313

Conversation

@axelray-dev

Copy link
Copy Markdown

Summary

On Python 3.13+, asyncio.Queue.shutdown() makes queue.get() raise the stdlib asyncio.QueueShutDown. EventProcessor only suppressed a local subclass of that exception, so the native instance was treated as an unexpected processor error and could emit error logs/telemetry during normal stop.

Changes

  • Catch/suppress the native asyncio.QueueShutDown (when present) in _process_queue and stop.
  • Keep the pre-3.13 local QueueShutDown fallback for artificial raises.
  • Add a unit regression that shuts down a native queue and asserts stop/process does not call telemetry/console error helpers.

Verification

  • uv run pytest tests/units/reflex_base/event/processor/test_event_processor.py -q (37 passed)
  • Ruff and targeted Pyright clean on touched files

Backwards compatibility

No public API change. Pre-3.13 behavior unchanged. Stop still drains and cancels as before; only expected shutdown exceptions are ignored correctly.

Fixes #6756

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a Python 3.13+ regression where asyncio.Queue.shutdown() raises the native asyncio.QueueShutDown base class, but the processor only suppressed the local subclass — meaning the base-class instance escaped as an unexpected error during normal shutdown. The fix introduces a _QUEUE_SHUTDOWN_ERRORS tuple, populated with asyncio.QueueShutDown on 3.13+ and the pre-existing local class otherwise, and uses it in both contextlib.suppress and the except clause.

  • event_processor.py: Adds _QUEUE_SHUTDOWN_ERRORS at module level (branched on hasattr(asyncio, \"QueueShutDown\")) and substitutes it everywhere QueueShutDown was previously caught directly.
  • test_event_processor.py: Adds a skipif-guarded regression test that shuts down a native queue, calls _process_queue and stop directly, and asserts that neither telemetry.send_error nor console.error is invoked.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to exception handling during shutdown, with no behavioural impact on the hot path.

The fix is minimal and targeted: it replaces a single exception class with a version-aware tuple in two catch sites, pre-3.13 behaviour is completely unchanged, and a new regression test directly exercises the 3.13+ code path.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-base/src/reflex_base/event/processor/event_processor.py Introduces _QUEUE_SHUTDOWN_ERRORS tuple to correctly catch the native asyncio.QueueShutDown (Python 3.13+) alongside the local subclass, fixing uncaught exceptions during shutdown
tests/units/reflex_base/event/processor/test_event_processor.py Adds a Python 3.13+-only regression test that verifies native asyncio.QueueShutDown is suppressed in both _process_queue and the queue task awaited during stop, asserting telemetry/console errors are not emitted
packages/reflex-base/news/6773.bugfix.md Changelog entry for the bugfix; missing trailing newline (cosmetic)

Reviews (2): Last reviewed commit: "add news fragment" | Re-trigger Greptile

@axelray-dev
axelray-dev marked this pull request as ready for review July 15, 2026 10:58
@axelray-dev
axelray-dev requested a review from a team as a code owner July 15, 2026 10:58
@masenf masenf added the In Review Actively being reviewed by reflex team member label Jul 29, 2026
masenf
masenf previously approved these changes Jul 29, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing axelray-dev:fix/queue-shutdown-py313 (c0a5c85) with main (a8857cd)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In Review Actively being reviewed by reflex team member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QueueShutDown subclass doesn't catch native asyncio.QueueShutDown on Python 3.13+ — spurious error logged on every shutdown

2 participants