Skip to content

Raise slow_callback_duration on synchronizer's internal event loop - #274

Draft
freider wants to merge 2 commits into
mainfrom
devin/1779960581-fix-remaining-async-blocking
Draft

Raise slow_callback_duration on synchronizer's internal event loop#274
freider wants to merge 2 commits into
mainfrom
devin/1779960581-fix-remaining-async-blocking

Conversation

@freider

@freider freider commented May 28, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #270 — the test_shutdown_during_ctx_mgr_setup failure at PR #273 CI is not caused by an actual blocking call.

Root cause

The synchronizer's background event loop runs in a daemon thread. When PYTHONASYNCIODEBUG=1 is set, asyncio.run() enables slow-callback detection on that loop with the default 0.1s threshold. On shared CI VMs (GitHub Actions), the background thread can be preempted by the OS for 100-300+ ms. Since asyncio measures wall-clock time (time.monotonic()), thread preemption during a task step is indistinguishable from actual blocking.

I verified this locally: even with asyncio.sleep(0.01) (not 0.3s), the run_coroutine_threadsafe callback — which just calls ensure_future() (microseconds of CPU work) — reports 0.119s under CPU stress.

Fix

Raise loop.slow_callback_duration from 0.1s to 0.5s on the synchronizer's internal event loop. This:

  • Preserves PYTHONASYNCIODEBUG=1 in subprocesses (no env stripping)
  • Still detects genuinely blocking calls (>0.5s)
  • Avoids false positives from OS scheduling jitter on shared CI infrastructure

Issue: N/A

Link to Devin session: https://modal.devinenterprise.com/sessions/bb383270f49d407bb997f528cf0f7c51
Requested by: @freider

The conftest autouse fixture sets PYTHONASYNCIODEBUG=1 to catch blocking
calls in the test process. This env var leaks into subprocesses via
inheritance, enabling asyncio's slow-callback detection on the
synchronizer's background event loop. On busy CI runners, normal task
steps can exceed the 0.1s threshold due to OS scheduling jitter,
producing spurious warnings on stderr that fail 'assert stderr == ""'
checks.

Strip PYTHONASYNCIODEBUG from the subprocess environment in
PopenWithCtrlC so the shutdown tests only test shutdown behavior, not
asyncio debug diagnostics.

Co-Authored-By: Elias Freider <elias@modal.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

The synchronizer's event loop runs in a background thread that shares
the process with other threads. On shared CI VMs (GitHub Actions etc.),
this thread can be preempted by the OS for 100-300+ ms. asyncio's
slow-callback detection measures wall-clock time (time.monotonic()),
so preemption during a task step appears as a 'slow callback' even
though no code is actually blocking.

Raise the threshold from the default 0.1s to 0.5s on the synchronizer's
internal loop so genuinely blocking calls (>0.5s) are still detected
while normal scheduling jitter doesn't produce spurious warnings on
stderr (which fail subprocess-based tests that assert stderr == '').

Co-Authored-By: Elias Freider <elias@modal.com>
@devin-ai-integration devin-ai-integration Bot changed the title Strip PYTHONASYNCIODEBUG from subprocess env in shutdown tests Raise slow_callback_duration on synchronizer's internal event loop May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant