Skip to content

Commit

Permalink
br: cancel context when timer stop (#56948) (#57007)
Browse files Browse the repository at this point in the history
ref #53480
  • Loading branch information
ti-chi-bot authored Nov 4, 2024
1 parent 64d4d21 commit bbf8742
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ func (trecv *timeoutRecv) Refresh() {
func (trecv *timeoutRecv) Stop() {
close(trecv.refresh)
trecv.wg.Wait()
trecv.cancel()
}

var TimeoutOneResponse = time.Hour
Expand Down
10 changes: 10 additions & 0 deletions br/pkg/backup/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,13 @@ func TestTimeoutRecvCancel(t *testing.T) {
cancel()
trecv.wg.Wait()
}

func TestTimeoutRecvCanceled(t *testing.T) {
ctx := context.Background()
cctx, cancel := context.WithCancel(ctx)
defer cancel()

tctx, trecv := StartTimeoutRecv(cctx, time.Hour)
trecv.Stop()
require.Equal(t, "context canceled", tctx.Err().Error())
}

0 comments on commit bbf8742

Please sign in to comment.