Skip to content

Commit

Permalink
Fix how we cancel the context when taking a builtin backup
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 8648264 commit 3d53b99
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 @@ -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

0 comments on commit 3d53b99

Please sign in to comment.