Skip to content

[Bug]: Test_Replayer9 loses context cancellation cause during WAL backend read #32946

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

The closed #21469 involved the same test but a different failure mode: its fix #21476 increased replay wait deadlines and added a timeout around ReplayWaitC. It did not address cancellation-cause propagation. The open #32912 concerns cancellation during skip-command Append retry backoff, which is also a different path.

Branch Name

main (observed in PR #32938 CI)

Commit ID

Tested PR head: 5def69e1136a472650f12d18150acd2d94e6d4cc
PR base: d2e71035dbae7471052ca5c0034d05827b926249

Other Environment Information

- Hardware parameters: GitHub Actions Ubuntu/x86 runner
- OS type: Ubuntu/x86
- Others: UT job https://github.com/matrixorigin/matrixone/actions/runs/44505921401/job/135497484102
- UT command: make ut UT_CONFIGURED=1 UT_PARALLEL=8 UT_TIMEOUT=40 UT_SHARD=all

Actual Behavior

Test_Replayer9 failed after 0.78 seconds. The failing assertion is at pkg/vm/engine/tae/logstore/driver/logservicedriver/replay_test.go:1790:

replay_test.go:1789: Read error: context canceled
replay_test.go:1790:
    Error Trace: .../logservicedriver/replay_test.go:1790
    Error:       Target error should be in err chain:
                 expected: "internal error: cancel"
                 in chain: "context canceled"
    Test:        Test_Replayer9
--- FAIL: Test_Replayer9 (0.78s)

The corresponding replay log shows that the error came back through the read-and-schedule path:

Wal-Replay-Info {
  "err-msg": "read and schedule error in loop: context canceled",
  "error": "context canceled"
}

The later line below is only a t.Logf message from the second replay, not the failing assertion:

replay_test.go:1837: Read error: internal error: cancel

That second value demonstrates the other cancellation path preserving the cause as expected.

Expected Behavior

After readCancel(cancelErr) cancels either replay, consumer.GetReplayState().Err() should retain the supplied cancellation cause. In particular:

assert.ErrorIs(t, readErr, cancelErr)

should hold whether cancellation is observed by the outer replay loop or while reading the next batch from the backend. The returned error should not depend on goroutine/read timing.

Steps to Reproduce

Observed in the CI job linked above. The test creates a context with context.WithCancelCause, runs ReplayForever, and then cancels it with:

cancelErr := moerr.NewInternalErrorNoCtx("cancel")
readCancel(cancelErr)
<-consumer.ReplayWaitC()
readErr := consumer.GetReplayState().Err()
assert.ErrorIs(t, readErr, cancelErr)

A focused stress command for reproducing the timing-dependent failure is:

go test ./pkg/vm/engine/tae/logstore/driver/logservicedriver \
  -run '^Test_Replayer9$' -count=100

This report is based on the executed CI failure and source tracing; the focused local stress run has not been performed as part of this report.

Additional information

Source trace and likely mechanism

There are two cancellation-error paths with different semantics:

  1. The outer replay loop in replayer.Replay uses context.Cause(ctx) when it observes ctx.Done() (replayer.go:462-471). This preserves the test's internal error: cancel cause.
  2. readNextBatch calls LogServiceDriver.readFromBackend (replayer.go:849-858). When the parent context is canceled, readFromBackend returns ctx.Err() in its cancellation checks (driver.go:380-383 and driver.go:399-401). This discards the specific cause and returns only context.Canceled.
  3. readNextBatch propagates that error to the replay loop, which returns through the read and schedule error in loop path before the outer ctx.Done() branch can replace it with context.Cause(ctx).

Therefore, cancellation during backend reading can produce context canceled, while cancellation observed by the outer replay loop produces internal error: cancel. This explains both values appearing in the same test log and why the failure is timing-dependent.

Scope

  • The observed failure is a UT failure and an inconsistency in cancellation-error propagation.
  • No data corruption or incorrect replayed entries are demonstrated by this failure.
  • PR perf(cdc): avoid formatting disabled watermark debug logs #32938 only changes pkg/cdc/watermark_updater.go; there is no evidence that its CDC logging optimization is involved in this logservice replay path.

Suggested fix and regression coverage

Preserve context.Cause(ctx) when the parent replay context is canceled, either in readFromBackend's parent-cancellation branches or at a single replay error-normalization boundary. Real backend errors and timeout causes should remain unchanged rather than being blindly replaced.

Regression coverage should exercise cancellation both before/around the outer replay ctx.Done() check and while the backend read is active, asserting errors.Is(err, cancelErr) in both cases. The existing second replay log shows that the outer-loop path already satisfies this contract.

Activity

  1. added
    kind/bug
    on Nov 19, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. added a commit that references this issue on Nov 20, 2026
    17df10b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions