diff --git a/cmd/pbm-agent/backup.go b/cmd/pbm-agent/backup.go index ac889dbc3..abe8e21cc 100644 --- a/cmd/pbm-agent/backup.go +++ b/cmd/pbm-agent/backup.go @@ -246,7 +246,7 @@ func (a *Agent) Backup(ctx context.Context, cmd *types.BackupCmd, opid types.OPI err = bcp.Run(bcpCtx, cmd, opid, l) a.unsetBcp() if err != nil { - if errors.Is(err, storage.ErrCancelled) { + if errors.Is(err, storage.ErrCancelled) || errors.Is(err, context.Canceled) { l.Info("backup was canceled") } else { l.Error("backup: %v", err) diff --git a/pbm/backup/backup.go b/pbm/backup/backup.go index 471fc0eb1..10398ffe2 100644 --- a/pbm/backup/backup.go +++ b/pbm/backup/backup.go @@ -181,7 +181,7 @@ func (b *Backup) Run(ctx context.Context, bcp *types.BackupCmd, opid types.OPID, defer func() { if err != nil { status := defs.StatusError - if errors.Is(err, storage.ErrCancelled) { + if errors.Is(err, storage.ErrCancelled) || errors.Is(err, context.Canceled) { status = defs.StatusCancelled } @@ -228,7 +228,7 @@ func (b *Backup) Run(ctx context.Context, bcp *types.BackupCmd, opid types.OPID, for { select { case <-tk.C: - err := query.BackupHB(context.Background(), b.cn.Conn, bcp.Name) + err := query.BackupHB(ctx, b.cn.Conn, bcp.Name) if err != nil { l.Error("send pbm heartbeat: %v", err) } @@ -258,7 +258,10 @@ func (b *Backup) Run(ctx context.Context, bcp *types.BackupCmd, opid types.OPID, } defer func() { - if !errors.Is(err, storage.ErrCancelled) || !inf.IsLeader() { + if !inf.IsLeader() { + return + } + if !errors.Is(err, storage.ErrCancelled) || !errors.Is(err, context.Canceled) { return }