Skip to content

Commit

Permalink
Fix how we cancel the context when restoring
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
frouioui committed Nov 26, 2024
1 parent 3d53b99 commit 4cc10e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,15 @@ func (be *BuiltinBackupEngine) restoreFiles(ctx context.Context, params RestoreP
wg := sync.WaitGroup{}

ctxCancel, cancel := context.WithCancel(ctx)
defer cancel()
defer func() {
// We may still have operations in flight that require a valid context, such as adding files to S3.
// Unless we encountered an error, we should not cancel the context. This is taken care of later
// in the process. If we encountered an error however, we can safely cancel the context as we should
// no longer work on anything and exit fast.
if err != nil {
cancel()
}
}()

for i := range fes {
wg.Add(1)
Expand Down

0 comments on commit 4cc10e5

Please sign in to comment.