Skip to content

Commit

Permalink
[release-21.0] Fix how we cancel the context in the builtin backup en…
Browse files Browse the repository at this point in the history
…gine (#17285) (#17291)

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
  • Loading branch information
vitess-bot[bot] authored Nov 28, 2024
1 parent f5603ba commit 985a501
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 985a501

Please sign in to comment.