From 4f0be5734f70e8963b7bb9bb9bff49d757d10bd7 Mon Sep 17 00:00:00 2001 From: Aaron Son Date: Thu, 6 Feb 2025 10:02:04 -0800 Subject: [PATCH] [no-release-notes] go/store/nbs: Check for context cancelation in SaveHashes. In certain cases, the work that SaveHashes does doesn't naturally see a context cancelation in a timely manner. Make certain we do return after we see one. --- go/store/nbs/store.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go/store/nbs/store.go b/go/store/nbs/store.go index e49daa8595..2ff69397c9 100644 --- a/go/store/nbs/store.go +++ b/go/store/nbs/store.go @@ -1821,6 +1821,13 @@ func (i *markAndSweeper) SaveHashes(ctx context.Context, hashes []hash.Hash) err var mu sync.Mutex first := true for { + // We manually check context here, because in some cases + // the work we are doing here does not result in a timely + // error once the context is canceled. + if ctx.Err() != nil { + return ctx.Err() + } + if !first { copy := toVisit.Copy() for h := range toVisit {