Raise slow_callback_duration on synchronizer's internal event loop - #274
Draft
freider wants to merge 2 commits into
Draft
Raise slow_callback_duration on synchronizer's internal event loop#274freider wants to merge 2 commits into
freider wants to merge 2 commits into
Conversation
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>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #270 — the
test_shutdown_during_ctx_mgr_setupfailure 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=1is 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), therun_coroutine_threadsafecallback — which just callsensure_future()(microseconds of CPU work) — reports 0.119s under CPU stress.Fix
Raise
loop.slow_callback_durationfrom 0.1s to 0.5s on the synchronizer's internal event loop. This:PYTHONASYNCIODEBUG=1in subprocesses (no env stripping)Issue: N/A
Link to Devin session: https://modal.devinenterprise.com/sessions/bb383270f49d407bb997f528cf0f7c51
Requested by: @freider