Skip to content

Commit

Permalink
fix backup goroutine leak (#15410)
Browse files Browse the repository at this point in the history
Signed-off-by: deepthi <deepthi@planetscale.com>
  • Loading branch information
deepthi committed Mar 6, 2024
1 parent fa2eaff commit 38ebdb3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,16 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupPara
var reader io.Reader = br
var writer io.Writer = bw

defer func() {
// Close the backupPipe to finish writing on destination.
if err := bw.Close(); err != nil {
createAndCopyErr = errors.Join(createAndCopyErr, vterrors.Wrapf(err, "cannot flush destination: %v", name))
}

if err := br.Close(); err != nil {
createAndCopyErr = errors.Join(createAndCopyErr, vterrors.Wrap(err, "failed to close the source reader"))
}
}()
// Create the gzip compression pipe, if necessary.
if backupStorageCompress {
var compressor io.WriteCloser
Expand Down Expand Up @@ -891,16 +901,7 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupPara
}

if err := createAndCopy(); err != nil {
return err
}

// Close the backupPipe to finish writing on destination.
if err = bw.Close(); err != nil {
return vterrors.Wrapf(err, "cannot flush destination: %v", name)
}

if err := br.Close(); err != nil {
return vterrors.Wrap(err, "failed to close the source reader")
return errors.Join(finalErr, err)
}

// Save the hash.
Expand Down

0 comments on commit 38ebdb3

Please sign in to comment.