Repository navigation
fix(concurrency): blocking engine work stays off the Swift cooperative pool - #725
Merged
Merged
Conversation
…e pool Every detached engine task ran on the cooperative pool, one thread per core that never grows: demuxer opens and packet reads, the live ingest's FIFO writes under backpressure, the native subtitle readers for the whole session, stop()'s waitForFinish, recording finish, probe closes. Each blocked job took a core's worth of async work out of the process, the host app's included. BlockingWork.detached creates the same task with an executor preference for BlockingExecutor, which runs jobs on GCD's global queues; those add a thread when one blocks. Awaits, main-actor hops and cancellation are unchanged. visionOS 1 has no TaskExecutor and keeps Task.detached. A test refuses any Task.detached that comes back into Sources/AetherEngine, and CI also runs the suite on a one-thread pool (LIBDISPATCH_COOPERATIVE_POOL_STRICT=1), which reproduces the 3-core runner's starvation deterministically on any Mac. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
…t hid behind the slow pace On the 3-core CI runner a handful of tests blocking pool threads starved the rest, so a different set of unrelated tests timed out every run: nine 120 s limits fired together at 151 s because their watchdog is a pool task too. The 34 suites measured blocking the pool (sample of a full run, leaf waits under completeTaskWithClosure) run under the new .offCooperativePool trait, and the AE#629 test models the engine's detached read through BlockingWork. The suite now runs in about 13 s instead of 72, which exposed tests that had leaned on the old pace: - LiveStartupAdmission: a parked job's 30 s deadline makes the gate return true, so a late test read it as an admission; the jobs now wait a day. - Issue281: a 3 s suffix stall could land before the late read; 60 s now, and the 200-body bound sits above the 4 MB the loopback buffers absorb. - SourceOpenRecovery: the retry can still be on its way when load() gives up. - RangedResponseIntegrity: the test's own read may refill legitimately; the over-delivery check now reads where that refill starts. - Issue243 / Issue445: process-wide memory figures beside parallel suites; best of three, and the census allocation on a VM tag of its own. - Issue605: 150 ms of quiet is not a park; SoftwarePacketReadAhead reports its producer's park the way VideoSegmentProvider reports parked waiters. - The five suites that clear the process-wide prewarm store run serialized against each other under one parent suite. Four full runs and one on a one-thread pool, all green. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
4 tasks done
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.
Summary
CI's
swift testwent red on a different set of unrelated tests nearly every run (#719, #723 and several runs on main). The cause is one mechanism: blocking work on the Swift cooperative pool, which has one thread per core and never grows. Thexcode-27-arm64runner has 3 cores. When a handful of jobs blocked, every other test starved, and so did the time-limit watchdogs: nine 120 s limits fired together at 151 s.The blocking came from both sides:
Task.detachedran on the pool. That covered demuxer opens and packet reads, the live ingest's FIFO writes under backpressure, the native subtitle readers for the whole session,stop()'swaitForFinish, recording finish and probe closes. This affects host apps too: on an Apple TV every blocked job takes a core's worth of async work out of the app.Measured locally by sampling a full run: 53 s of blocked pool time in a 24 s run.
LIBDISPATCH_COOPERATIVE_POOL_STRICT=1(a one-thread pool) reproduces the CI failure on any Mac: 26 issues across 470 s before this change.What changed
BlockingWork.detachedcreates the same detached task with an executor preference forBlockingExecutor, which runs jobs on GCD's global queues; those add a thread when one blocks. Awaits, main-actor hops and cancellation are unchanged. visionOS 1 has noTaskExecutorand keepsTask.detached.Task.detachedinSources/AetherEnginegoes through it, and a test refuses new ones..offCooperativePooltrait (34 suites, chosen from the sample).docs/architecture.mdgains a section on blocking work and the cooperative pool, anddocs/api.mdwarns hosts that a detached task is no background thread.Test plan
swift testruns (both runners) and one Swift Testing run on a one-thread pool, all green.BlockingWorkswitched back to plainTask.detached, the new blocked-jobs test hangs on a one-thread pool, and the time-limit watchdog never gets to run, the same as on the runner.Scripts/check-doc-links.pypasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS