Skip to content

hash: async_heavy_test's responsive check orders the timer before the completion through a latch, never through the scheduler - #8

Merged
pinhopro merged 1 commit into
mainfrom
fix/async-heavy-flake
Nov 20, 2026
Merged

pinhopro merged 1 commit into
mainfrom
fix/async-heavy-flake

Conversation

@pinhopro

@pinhopro pinhopro commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Cause

check_responsive in test/async_heavy_test.cpp started an Argon2id of 64 MiB on the pool and a 10 ms timer on the caller's io_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 when run() starts, and Windows's scheduler (IOCP) dispatches it before the expired timer.

Evidence:

  • CI run 44690351573, job "CI / MSVC 14.3 (Visual Studio 2022)": async_heavy_test.cpp(898): test 'timer_fired_first' failed in function check_responsive, after passing in earlier runs.
  • Reproduced deterministically on the local msvc-lane (MSVC 14.3 under Wine) by sleeping 500 ms between the call and context.run(): the work had completed (pool done=1) and timer_fired_first failed 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

  • With the 500 ms delay injected, async_heavy and async_heavy_no_exceptions pass on MSVC 14.3 under Wine (msvc-lane) and natively (clang, macOS); without it they pass too.
  • clang-format clean; macOS full lint (tools/lint/lint.sh) on the superproject with this commit.

Not changed here

example/async_argon2id.cpp makes 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

… 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.
@pinhopro
pinhopro merged commit 22ce9da into main Nov 20, 2026
21 of 31 checks passed
@pinhopro
pinhopro deleted the fix/async-heavy-flake branch November 20, 2026 11:03
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