Skip to content

Commit

Permalink
br: cancel context when timer stop (#56948) (#57009)
Browse files Browse the repository at this point in the history
ref #53480
  • Loading branch information
ti-chi-bot authored Oct 31, 2024
1 parent e1ae550 commit a86aac9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion br/pkg/backup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ go_test(
embed = [":backup"],
flaky = True,
race = "on",
shard_count = 12,
shard_count = 13,
deps = [
"//br/pkg/conn",
"//br/pkg/gluetidb",
Expand Down
1 change: 1 addition & 0 deletions br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ func (trecv *timeoutRecv) Refresh() {
func (trecv *timeoutRecv) Stop() {
close(trecv.refresh)
trecv.wg.Wait()
trecv.cancel(nil)
}

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 a86aac9

Please sign in to comment.