Skip to content

Commit

Permalink
Fix how we cancel the context in the builtin backup engine (#17285)
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
vitess-bot[bot] authored and vitess-bot committed Nov 27, 2024
1 parent f5603ba commit f31c28e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,15 @@ func (be *BuiltinBackupEngine) backupFiles(
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 finalErr != nil {
cancel()
}
}()

for i := range fes {
wg.Add(1)
Expand Down Expand Up @@ -1037,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 f31c28e

Please sign in to comment.