{"record":{"id":"14b40b7c4675e359","repo":"vitessio/vitess","slug":"copyall-was-interrupted-due-to-context-expiration","errorCode":null,"errorMessage":"CopyAll was interrupted due to context expiration","messagePattern":"CopyAll was interrupted due to context expiration","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go","lineNumber":316,"sourceCode":"\t\treturn nil\n\t}, vstreamOptions)\n\n\tif copyWorkQueue != nil {\n\t\tcopyWorkQueue.close()\n\t}\n\n\t// Drain late-arriving task results and aggregate.\n\tif terr := drainAndAggregateErrors(resultCh, serr, preTerrs); terr != nil {\n\t\tlog.Warn(fmt.Sprintf(\"task errors in workflow %s: %v\", vc.vr.WorkflowName, terr))\n\t\treturn terr\n\t}\n\n\t// A context expiration was probably caused by a PlannedReparentShard or an\n\t// elapsed copy phase duration. CopyAll is not resilient to these events.\n\tselect {\n\tcase <-ctx.Done():\n\t\tlog.Info(fmt.Sprintf(\"Copy of %v stopped\", state.currentTableName))\n\t\treturn errors.New(\"CopyAll was interrupted due to context expiration\")\n\tdefault:\n\t\tif err := vc.runPostCopyActionsAndDeleteCopyState(ctx, stopCtx, state.currentTableName); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := vc.updatePos(ctx, gtid); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tlog.Info(\"Completed copy of all tables\")\n\t}\n\treturn nil\n}\n\n// runPostCopyActionsAndDeleteCopyState runs post copy actions and deletes the\n// copy state entry for a table, signifying that the copy phase is complete for\n// that table.\nfunc (vc *vcopier) runPostCopyActionsAndDeleteCopyState(ctx, stopCtx context.Context, tableName string) error {\n\tif err := vc.vr.execPostCopyActions(ctx, stopCtx, tableName); err != nil {\n\t\treturn vterrors.Wrapf(err, \"failed to execute post copy actions for table %q\", tableName)","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vcopier_atomic.go#L298-L334","documentation":"CopyAll detects that its context expired during the copy loop and aborts with this error, because the copy phase is not resilient to context cancellation. The context was likely killed by a PlannedReparentShard (PRS) or the configured copy phase duration elapsing.","triggerScenarios":"ctx.Done() fires while copyAll is mid-table-copy — caused by a PlannedReparentShard demoting/moving the tablet, or the workflow's copy-phase-duration timeout expiring before the bulk copy finished.","commonSituations":"Large datasets that exceed the copy phase time limit; a reparent happening during a MoveTables/Materialize copy; vreplication workflow cancel/timeout settings too aggressive.","solutions":["Increase the workflow's copy phase duration (e.g. --copy_phase_duration / vreplication_copy_phase_duration flag) so large copies finish","Avoid running PlannedReparentShard while a copy is active; retry the copy after the reparent completes","Check for slow copy performance (source load, network, bandwidth throttling) and optimize; copies automatically resume from copy state on retry"],"exampleFix":"// before\nvtctldclient MoveTables --workflow wf --target-commerce ks --tables big_table   # copy exceeds default phase duration\n// after\nvtctldclient MoveTables --workflow wf --target-commerce ks --tables big_table --copy-phase-duration 24h","handlingStrategy":"retry","validationCode":"// Estimate copy size vs allowed phase duration before starting\nrowEst, _ := srcConn.FetchRow(\"SELECT SUM(table_rows) FROM information_schema.tables WHERE table_schema IN (?)\", args)\nif rowEst > 10_000_000 { setCopyPhaseDuration(\"24h\") }","typeGuard":null,"tryCatchPattern":"err := workflow.Start(ctx)\nif errors.Is(err, errCopyInterrupted) || strings.Contains(err.Error(), \"interrupted due to context expiration\") {\n    // Copy state allows resume; retry with longer phase duration and no concurrent PRS\n    ctx = context.Background()\n    return workflow.Resume(ctx)\n}","preventionTips":["Increase copy_phase_duration for large tables","Avoid PlannedReparentShard during active copy phases","Monitor copy progress to size timeouts realistically"],"tags":["vreplication","vcopier","context-expired","copy-timeout"],"backgroundTag":"context-deadline-exceeded","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}