Skip to content

test(syncer): hold a crashed notesd at its crash point until it stops - #142

Merged
bketelsen merged 2 commits into
mainfrom
fix/syncer-crash-test-halts-until-stop
Nov 9, 2026
Merged

bketelsen merged 2 commits into
mainfrom
fix/syncer-crash-test-halts-until-stop

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare failed on main's scheduled CI run 42633073293 (job "Race detector"). The push run on the same commit, 5b9c142, passed:

crashapply_test.go:474: a's heads being applied while the share is away = [], <nil>; want the delete of f.md
crashapply_test.go:476: the device pushed [{... Path:f.md Hash: ... Status:accepted ...}], but changed nothing itself

Cause: a timing gap in the test harness, not a race in the syncer. The crashy device's crash hook cut the network and returned. The crashed notesd then ran on until down() called Stop. In that gap, the sync loop (loop.run) waited its 10 ms test backoff, or woke at once on a pending kick, and ran finishApplying again. The vault's scan had succeeded and f.md was 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) before d.srv.Stop() in down(), as on a loaded runner, the test failed 5 of 5 runs on main with the CI messages above.

Fix: the crash hook now waits for a new rpctest.Server.Done(). Stop closes it right after its cancel() 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 own Done channel: 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 on 10def79; guard TestDoneClosesAfterDerivedContextsEnd and 1 .memory/corrections.jsonl line). 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. Every crashy crash point in this file fires in the sync loop's pull apply, not inside an RPC handler, so the hold cannot block Stop's Run.Stop.

internal/synctest crashes 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/rpctest is test infrastructure: only tests and internal/synctest import it, and notesd does not. No path matches .github/risk-paths.json.

Verification

  • make check green (host)
  • go test -race -count=50 -run TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare ./internal/syncer/: ok
  • Revert test (timing): the failure needs a delay between the crash and the stop. So the targeted test runs with the 100 ms probe sleep before d.srv.Stop() in down():
    • at main (without the fix): go test -race -count=5 -run TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare ./internal/syncer/ fails 5 of 5 with crashapply_test.go:474/:476
    • with the fix: the same command passes 5 of 5. With -count=10 over TestADeleteInterruptedBeforeTheRemovalWaitsForTheShare|TestACrash, all pass.
    • The probe is not committed.
  • Revert test for the guard: in a scratch worktree at 56c9ef6, Done() changed back to s.ctx.Done(); go test -race -count=5 -run TestDoneClosesAfterDerivedContextsEnd ./internal/rpctest/ fails on its assertion (19584 of 20000 are still live and similar); at the head it passes.
  • Blocking review point fixed: guard added and 1 .memory/corrections.jsonl line added

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.
@frostyard-machines frostyard-machines added level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge labels Nov 9, 2026
@bketelsen
bketelsen merged commit c1107de into main Nov 9, 2026
9 checks passed
@bketelsen
bketelsen deleted the fix/syncer-crash-test-halts-until-stop branch November 9, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants