Put a call in both states so the seam's own guard is pinned
The last pass's only non-comment source change was held by nothing. Reverting the hold's guard so it fires unconditionally survived all five scenarios, because no scenario ever had a call in both states at once: the timeout scenario never arms the hold, and the hold scenarios never let a timeout expire. `holdtimeout` is the missing state. The hold is armed, the runtime is idle, and one poll asks for 150 ms while the hold stays armed for 800. A call the wait woke is the seam's to park; a call whose own timeout expired is on its way out, and parking it would let `holdclose` report the bridge keeping a host call inside the library when what kept it was the fixture. The measurement is which of those two numbers the poll comes back at. Two entries, and the loosening is the one worth reading: the same two conditions in the other order. The hold blocks, so the order is the rule — asked first, it parks the call and then decides whether it should have. Both die on `holdtimeout` at about 800 ms and on nothing else; `holdclose` and `latecall` stay green under both, which is the point. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c682619fbd
commit
5ab4c627d7
2 changed files with 107 additions and 11 deletions
|
|
@ -21,6 +21,7 @@
|
|||
// cultmesh_quic_native_tests holdclose [iterations] [pollers]
|
||||
// cultmesh_quic_native_tests polltimeout [iterations]
|
||||
// cultmesh_quic_native_tests latecall [iterations]
|
||||
// cultmesh_quic_native_tests holdtimeout [iterations]
|
||||
//
|
||||
// `closerace` hunts the race: many pollers, many iterations, and whatever the
|
||||
// schedule gives. `holdclose` takes the guessing out of it — the bridge's
|
||||
|
|
@ -34,6 +35,10 @@
|
|||
// passes both. `polltimeout` is the one that lets the timeout govern the return
|
||||
// and measures it. `latecall` covers the other half of section 4: a call that
|
||||
// races the start of a close is refused rather than counted behind its wait.
|
||||
// `holdtimeout` covers the seam's own rule, which nothing else is in a position
|
||||
// to see: the hold parks a call the wait woke and not one whose own timeout
|
||||
// expired, so the quiesce the hold scenarios assert is the bridge's doing and
|
||||
// not the fixture's.
|
||||
//
|
||||
// Exit code 0 means every assertion held. Anything else, including a sanitizer
|
||||
// abort or the bridge's own assertion, is a failure. Under ThreadSanitizer run
|
||||
|
|
@ -569,6 +574,69 @@ std::string LateCallOnce() {
|
|||
return {};
|
||||
}
|
||||
|
||||
// How long `holdtimeout`'s poll asks for, and how long the hold stays armed
|
||||
// under it. The gap between them is the whole measurement: a poll the hold
|
||||
// parks leaves when the hold is released, so its elapsed time lands at the
|
||||
// second number instead of the first.
|
||||
constexpr int32_t kHeldTimeoutPollMs = 150;
|
||||
constexpr int kHoldArmedMs = 800;
|
||||
|
||||
// The seam's own rule, and the only scenario that can see it: the hold parks a
|
||||
// call the wait woke, and not one whose own timeout expired.
|
||||
//
|
||||
// Everything else that arms the hold parks a woken call, so the guard governs
|
||||
// nothing either of them observes — the timeout scenario never arms the hold,
|
||||
// and the hold scenarios never let a timeout expire, so nothing was ever in
|
||||
// both states at once and the guard could be deleted with every scenario still
|
||||
// green. This puts one call in both states: the hold is armed, and the runtime
|
||||
// is idle, so the wait ends on the timeout and the call is on its way out.
|
||||
//
|
||||
// It matters because a scenario that parked such a call would then report the
|
||||
// bridge keeping a host call inside the library when what kept it was the
|
||||
// fixture — the quiesce numbers `holdclose` asserts would be the seam's, not
|
||||
// the bridge's.
|
||||
std::string HoldTimeoutOnce() {
|
||||
cultmesh_quic_debug_hold_calls(1);
|
||||
void* runtime = nullptr;
|
||||
const int32_t opened = cultmesh_quic_runtime_open("cultmesh-quic-native-tests", &runtime);
|
||||
if (opened != 0 || runtime == nullptr) {
|
||||
cultmesh_quic_debug_hold_calls(0);
|
||||
return "cultmesh_quic_runtime_open returned " + std::to_string(opened);
|
||||
}
|
||||
|
||||
// On a thread of its own, because a parked call does not come back until the
|
||||
// release below and this thread is what releases it.
|
||||
TimedPoll poll{};
|
||||
std::thread poller([runtime, &poll] { poll = PollFor(runtime, kHeldTimeoutPollMs); });
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(kHoldArmedMs));
|
||||
cultmesh_quic_debug_hold_calls(0);
|
||||
poller.join();
|
||||
cultmesh_quic_runtime_close(runtime);
|
||||
|
||||
if (poll.result != 0)
|
||||
return "a poll ended by its own timeout returned " + std::to_string(poll.result) +
|
||||
", not the 0 an idle runtime owes it";
|
||||
if (poll.elapsed_ms < kHeldTimeoutPollMs - kEarlyToleranceMs)
|
||||
return "a poll asking for " + std::to_string(kHeldTimeoutPollMs) + " ms returned after " +
|
||||
std::to_string(poll.elapsed_ms) + " ms, so the fixture never let its timeout run out";
|
||||
if (poll.elapsed_ms > kHeldTimeoutPollMs + LateToleranceMs(kHeldTimeoutPollMs))
|
||||
return "a poll asking for " + std::to_string(kHeldTimeoutPollMs) + " ms returned after " +
|
||||
std::to_string(poll.elapsed_ms) + " ms: the hold parked a call its own timeout had "
|
||||
"already ended, and it left when the hold did";
|
||||
return {};
|
||||
}
|
||||
|
||||
int HoldTimeout(int iterations) {
|
||||
for (int iteration = 0; iteration < iterations; ++iteration) {
|
||||
const std::string failure = HoldTimeoutOnce();
|
||||
if (!failure.empty())
|
||||
return Fail("holdtimeout iteration " + std::to_string(iteration) + ": " + failure);
|
||||
}
|
||||
std::printf("holdtimeout %dx: ok\n", iterations);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LateCall(int iterations) {
|
||||
for (int iteration = 0; iteration < iterations; ++iteration) {
|
||||
const std::string failure = LateCallOnce();
|
||||
|
|
@ -606,7 +674,8 @@ int CloseRace(int iterations, int pollers) {
|
|||
int main(int argc, char** argv) {
|
||||
if (argc < 2) {
|
||||
std::fprintf(stderr,
|
||||
"usage: %s closerace|holdclose|polltimeout|payloadfit|latecall [iterations] [pollers]\n",
|
||||
"usage: %s closerace|holdclose|holdtimeout|polltimeout|payloadfit|latecall "
|
||||
"[iterations] [pollers]\n",
|
||||
argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
|
@ -620,9 +689,10 @@ int main(int argc, char** argv) {
|
|||
if (scenario == "closerace") return CloseRace(iterations, pollers);
|
||||
if (scenario == "polltimeout") return PollTimeout(iterations);
|
||||
if (scenario == "payloadfit") return PayloadFit(iterations);
|
||||
if (scenario == "holdclose" || scenario == "latecall") {
|
||||
if (scenario == "holdclose" || scenario == "latecall" || scenario == "holdtimeout") {
|
||||
#if defined(CULTMESH_QUIC_DEBUG_ASSERTS)
|
||||
if (scenario == "latecall") return LateCall(iterations);
|
||||
if (scenario == "holdtimeout") return HoldTimeout(iterations);
|
||||
return HoldClose(iterations, pollers);
|
||||
#else
|
||||
std::fprintf(stderr,
|
||||
|
|
|
|||
|
|
@ -519,6 +519,30 @@ const mutations = [
|
|||
old: "std::chrono::milliseconds(timeout_ms),",
|
||||
new: "std::chrono::milliseconds((std::min)(timeout_ms, 1000)),",
|
||||
},
|
||||
// The seam's own rule, and the only non-comment source change of the last pass
|
||||
// that nothing pinned. It is development-only and folds away in release, so
|
||||
// nothing shipped was at risk; it is still the shape this campaign keeps
|
||||
// finding, a change justified by a scenario that cannot observe it. The
|
||||
// timeout scenario never armed the hold and the hold scenarios never let a
|
||||
// timeout expire, so no call was ever in both states and the guard could be
|
||||
// deleted with everything green. `holdtimeout` puts one call in both.
|
||||
{
|
||||
target: "native",
|
||||
honestOn: ["linux-x64", "win32-x64"],
|
||||
rule: "the hold parks only a call the wait woke (revert: it parks whatever reaches it)",
|
||||
old: " if (woken && CULTMESH_QUIC_DEBUG_HELD(lock)) return 0;\n",
|
||||
new: " if (CULTMESH_QUIC_DEBUG_HELD(lock)) return 0;\n",
|
||||
},
|
||||
{
|
||||
target: "native",
|
||||
honestOn: ["linux-x64", "win32-x64"],
|
||||
// The spelling nobody would look twice at: the same two conditions, the
|
||||
// other way round. The hold blocks, so the order is the rule — asked first,
|
||||
// it parks the call and then decides whether it should have.
|
||||
rule: "the hold parks only a call the wait woke (loosening: it decides after parking)",
|
||||
old: " if (woken && CULTMESH_QUIC_DEBUG_HELD(lock)) return 0;\n",
|
||||
new: " if (CULTMESH_QUIC_DEBUG_HELD(lock) && woken) return 0;\n",
|
||||
},
|
||||
// The close's wake. It was defended by committed code and had no entry, so the
|
||||
// table understated what `closerace` covers; these say it.
|
||||
{
|
||||
|
|
@ -698,19 +722,21 @@ function testsPass(workspace) {
|
|||
// ThreadSanitizer build is the only thing that sees a notify land on a destroyed
|
||||
// condition variable, and it exists on linux-x64 alone.
|
||||
//
|
||||
// `holdclose` and `latecall` run only where the development seam exists, which
|
||||
// is the assertion build: they drive the quiesce and the refusal through that
|
||||
// seam rather than through a sleep, and they are what kill the rules about
|
||||
// counting a host call at all. The ThreadSanitizer build deliberately keeps the
|
||||
// shipped shape — no assertions, no seam — because what it is there for is the
|
||||
// race in a library built like the one that ships.
|
||||
// `holdclose`, `latecall` and `holdtimeout` run only where the development seam
|
||||
// exists, which is the assertion build: they drive the quiesce and the refusal
|
||||
// through that seam rather than through a sleep, and they are what kill the
|
||||
// rules about counting a host call at all. The ThreadSanitizer build
|
||||
// deliberately keeps the shipped shape — no assertions, no seam — because what
|
||||
// it is there for is the race in a library built like the one that ships.
|
||||
//
|
||||
// `polltimeout` measures a wait against the timeout it asked for, so it is run
|
||||
// only where nothing distorts the clock: a sanitizer's slowdown would make its
|
||||
// bands meaningless, which is the honest limit of that entry.
|
||||
// `polltimeout` and `holdtimeout` both measure a wait against the timeout it
|
||||
// asked for, so they are run only where nothing distorts the clock: a
|
||||
// sanitizer's slowdown would make their bands meaningless, which is the honest
|
||||
// limit of those entries.
|
||||
const assertScenarios = [
|
||||
["holdclose", "3", "64"],
|
||||
["latecall", "5"],
|
||||
["holdtimeout", "3"],
|
||||
["polltimeout", "3"],
|
||||
["payloadfit", "3"],
|
||||
["closerace", "20", "256"],
|
||||
|
|
|
|||
Loading…
Reference in a new issue