Skip to content

[Bug] Backup ignores caller cancellation while copying object files #26246

Closed

Description

@Ariznawlll

Summary

Object-file copying during a backup no longer observes the context passed to BackupData. Once copying has started, cancellation or a deadline on the caller does not make the backup return until the active file operation itself finishes.

Reproduction

  1. Start a backup that reaches parallelCopyData with a file service whose Read(ctx, ...) waits for its context to finish.
  2. Cancel the context originally passed to the backup after Read has started.
  3. The copy remains waiting; it returns only after the test manually releases the file service.

The behavior reproduced 3/3 times on 8c9bb66898afa74f8b231e1915d99489ae8a0da7.

Actual behavior

execBackup receives the caller context, but parallelCopyData initializes each job with context.Background() and invokes CopyFileWithRetry(context.Background(), ...). The worker wait is unbounded, so a blocked copy keeps the backup request active after the caller has cancelled it.

Expected behavior

The copy jobs and retry loop should derive from the backup caller context. A cancelled or expired backup request should return promptly and stop waiting for outstanding copy work.

Impact

A backup operation can remain active longer than its caller allows when a storage read or write does not finish.

Activity

  1. added this to the MO-202607 milestone on Jul 27, 2026
  2. added
    kind/bug
    on Jul 27, 2026
  3. added theissue type on Jul 27, 2026
  4. LeftHandCold commented on Jul 28, 2026

    @LeftHandCold
    Collaborator

    已在当前 main(6004becb56adc7f4d22dbfb9554bef8d7091e25d)确认是生产可达的真实问题。

    根因是 BackupData 虽然收到 caller context,但 parallelCopyData 创建 job 和调用 CopyFileWithRetry 时都换成了 context.Background();同时旧的 retry helper 也不能在 backoff 中响应取消。另一个并发边界是单槽 errC 会让多个失败 worker 阻塞,函数提前 return/close 后存在生命周期风险。

    修复 PR:#26289

    修复会贯穿 caller context、用 cancel cause 保留首个根因并取消兄弟任务、有界接单且等待所有已提交任务退出,同时改用 context-aware retry。新增 blocked read、retry backoff、兄弟任务取消的确定性回归;pkg/backup 完整 non-race/race、focused -race -count=100、build/vet 和 pkg/datasync.TestCopyFile 均通过。

  5. LeftHandCold commented on Jul 31, 2026

    @LeftHandCold
    Collaborator

    fixed

  6. added
    severity/s0
    and removed on Jul 31, 2026
  7. Ariznawlll commented on Aug 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:6b3ad84c9d01d453c2bcdd0f440637350e3aa8c6
    • 测试日期:2026-08-02
    • 验证方式:官方 main 源码构建;在 pkg/backup 对复制 read 与 retry backoff 做确定性阻塞/取消注入,并运行正常复制控制。

    原问题验证

    原问题是调用方取消备份后,复制任务错误使用独立背景 context,仍继续复制或在 retry backoff 中等待。本轮定向测试连续执行 3 轮:在 read 已经开始后取消 caller context,任务均及时以 context canceled 返回;在 retry backoff 中取消也立即停止,而非等待下一次重试。

    Happy Path 覆盖

    1. TestCopyFileWithRetry 和成功 provider-copy 控制路径连续 3 轮通过。
    2. TestBackupData 连续 3 轮完成备份、重启、恢复和扫描校验,未影响正常备份链路。

    Unhappy Path 覆盖

    1. 复制 read 已开始后取消 caller context:返回 context canceled。
    2. retry backoff 期间取消:不继续等待下一轮重试。
    3. 首个 worker 失败后:取消已投递的 sibling,并等待其退出;不会遗留后台复制任务。

    白盒验证

    取消时序和 retry backoff 需要可控阻塞点,采用 TestParallelCopyDataHonorsCallerCancellation、TestCopyFileWithRetryStopsDuringBackoff 等确定性包内测试;定向 go test -race ./pkg/backup -run '^TestParallelCopyDataHonorsCallerCancellation$' 通过(ok .../pkg/backup 1.897s)。相关回归位于 pkg/backup/tae_parallel_copy_test.go。

    回归测试

    该问题需要控制 FileService 阻塞与取消时序,回归保持在 pkg/backup 白盒测试;不适合作为普通 motr SQL 黑盒 case。

    测试证据

    取消、backoff、sibling 生命周期和正常复制定向用例 -count=3 全部通过:ok github.com/matrixorigin/matrixone/pkg/backup 0.905s;完整备份恢复控制 -count=3 通过:ok github.com/matrixorigin/matrixone/pkg/backup 5.286s。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions