Repository navigation
test(syncer): hold a crashed notesd at its crash point until it stops - #142
Merged
Merged
Conversation
TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare failed on the race detector run: after its "applying" crash point fired, the crashed notesd ran on until down() stopped it. In that gap its sync loop, after its 10 ms backoff, ran finishApplying again: the vault's scan had succeeded and f.md was still on disk, so it settled the delete record the crash left, which the test then expects to find after the restart. A real crash ends the process, so this is the test's own gap, not a fault of the syncer. The crash hook now waits for the new rpctest.Server.Done, closed when Stop ends the context of the vault actors, the hub and the sync loops. The loop returns as soon as the hook does, and nothing of the crashed notesd runs after the crash.
Server.Done returned the server context's own Done channel. Go closes a parent's Done channel before it cancels the contexts derived from it, so a crash hook woken by it could resume while the sync loop's context (derived in internal/syncer/syncer.go) was still live, and the loop could still settle the record the crash left. Stop now closes a separate channel right after cancel returns, which is after every derived context has ended, and before it waits for the goroutines. TestDoneClosesAfterDerivedContextsEnd checks the order. The Done comment also says that a crash point inside an RPC handler must not wait for it, since Stop first waits for the handlers.
bketelsen
approved these changes
Nov 9, 2026
6 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
TestADeleteInterruptedBeforeTheRemovalWaitsForTheSharefailed on main's scheduled CI run 42633073293 (job "Race detector"). The push run on the same commit,5b9c142, passed:Cause: a timing gap in the test harness, not a race in the syncer. The
crashydevice's crash hook cut the network and returned. The crashed notesd then ran on untildown()calledStop. In that gap, the sync loop (loop.run) waited its 10 ms test backoff, or woke at once on a pending kick, and ranfinishApplyingagain. The vault's scan had succeeded andf.mdwas still on disk, so the loop correctly settled (deleted) the delete record that the crash left. After the restart, the test expects to find that record. A real crash ends the process, so production cannot take this path.Proof: with a temporary
time.Sleep(100 * time.Millisecond)befored.srv.Stop()indown(), as on a loaded runner, the test failed 5 of 5 runs onmainwith the CI messages above.Fix: the crash hook now waits for a new
rpctest.Server.Done().Stopcloses it right after itscancel()returns, so after every derived context (the vault actors', the hub's, the sync loops') has ended, and before it waits for the goroutines. It is not the context's ownDonechannel: Go closes a parent's channel before it cancels the derived contexts, so a woken hook could still find the loop's context live (cross-review finding on10def79; guardTestDoneClosesAfterDerivedContextsEndand 1.memory/corrections.jsonlline). The crashed goroutine holds at the crash point until the stop. Then the loop finds its context ended and returns. Nothing of the crashed notesd runs after the crash. No sleeps. Everycrashycrash point in this file fires in the sync loop's pull apply, not inside an RPC handler, so the hold cannot blockStop'sRun.Stop.internal/synctestcrashes inside an RPC write and is not changed. Its oracle checks convergence only, so the same gap does not affect its verdicts.No issue exists for this flake. #128 is a different one (
TestRPCShutdownStopsNotesdAfterItAnswers). In the last 15 failed CI runs, this test failed only in this one.Risk tier
Risk tier: 1 — tests only.
internal/rpctestis test infrastructure: only tests andinternal/synctestimport it, and notesd does not. No path matches.github/risk-paths.json.Verification
make checkgreen (host)go test -race -count=50 -run TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare ./internal/syncer/: okd.srv.Stop()indown():main(without the fix):go test -race -count=5 -run TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare ./internal/syncer/fails 5 of 5 withcrashapply_test.go:474/:476-count=10overTestADeleteInterruptedBeforeTheRemovalWaitsForTheShare|TestACrash, all pass.56c9ef6,Done()changed back tos.ctx.Done();go test -race -count=5 -run TestDoneClosesAfterDerivedContextsEnd ./internal/rpctest/fails on its assertion (19584 of 20000 are still liveand similar); at the head it passes..memory/corrections.jsonlline added