Repository navigation
hash: async_heavy_test's responsive check orders the timer before the completion through a latch, never through the scheduler - #8
Merged
Conversation
… completion through a latch, never through the scheduler check_responsive started an Argon2id of 64 MiB on the pool and a 10 ms timer on the caller's io_context, and asserted that the timer's handler ran before the completion's. Nothing ordered the two: when the caller's thread was descheduled, on a loaded runner, for longer than the derivation took, the completion was queued before the loop ran, and Windows's scheduler (IOCP) ran it before the expired timer (CI run 44690351573, MSVC 14.3, async_heavy_no_exceptions: timer_fired_first failed). A delay of 500 ms between the call and the loop's run reproduces it on the msvc-lane every time. The check now runs the same libsodium Argon2id of 64 MiB on a backend of the test, `latched`, which then waits, off the caller's thread, until the test opens its latch. The loop runs once the work has started on the pool, and the timer's handler, which finds the work not completed, opens the latch: the completion cannot come first, whatever the scheduler does, and the result is still the synchronous function's. The same 500 ms delay now passes, natively and on MSVC under Wine. On the caller's thread the latch is not waited for, so that a work run there cannot hang the test.
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.
Cause
check_responsiveintest/async_heavy_test.cppstarted an Argon2id of 64 MiB on the pool and a 10 ms timer on the caller'sio_context, then asserted that the timer's handler ran before the completion's (timer_fired_first). Nothing ordered the two: when the caller's thread is descheduled, on a loaded runner, for longer than the derivation takes, the completion is already queued whenrun()starts, and Windows's scheduler (IOCP) dispatches it before the expired timer.Evidence:
async_heavy_test.cpp(898): test 'timer_fired_first' failed in function check_responsive, after passing in earlier runs.context.run(): the work had completed (pool done=1) andtimer_fired_firstfailed at the same assertion. Natively on macOS the same delay passed, because the reactor scheduler happens to run the timer first: the outcome depended on the scheduler, not on the code under test.Fix
The check now runs the same libsodium Argon2id of 64 MiB on a test backend,
latched, which after deriving waits (off the caller's thread) until the test opens its latch. The loop runs once the work has started on the pool; the timer's handler, which finds the work not completed, opens the latch. The completion cannot come first whatever the scheduler does, and the result is still compared with the synchronous function's. On the caller's thread the latch is not waited for, so a work run there cannot hang the test. Nothing the check proves is weakened: a heavy work in flight on the pool, and a handler of the caller's loop running meanwhile.Verification
async_heavyandasync_heavy_no_exceptionspass on MSVC 14.3 under Wine (msvc-lane) and natively (clang, macOS); without it they pass too.tools/lint/lint.sh) on the superproject with this commit.Not changed here
example/async_argon2id.cppmakes the same kind of claim in its expected output ("the loop ran meanwhile: yes", a 1 ms timer against a 64 MiB Argon2id) and is exposed to the same race, with a wider margin. It is a documentation example without test backends, so it needs a design decision of its own.The superproject's gitlink bump is webcpporg/webcpp#42.
🤖 Generated with Claude Code