Skip to content

Commit

Permalink
handle context.Canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
defbin committed Sep 28, 2023
1 parent b27e39f commit cb02c48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/pbm-agent/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions pbm/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit cb02c48

Please sign in to comment.