From 42bb0f47f1c58d5b00b904c6385099b346a1d23e Mon Sep 17 00:00:00 2001 From: sumeerbhola Date: Mon, 16 Dec 2024 13:06:46 -0500 Subject: [PATCH] cache: tiny tweaks to readShard - acquire a read lock instead of a write lock, when context is canceled. - add another assertion. --- internal/cache/read_shard.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/cache/read_shard.go b/internal/cache/read_shard.go index 432edc1e4c..474433b1c8 100644 --- a/internal/cache/read_shard.go +++ b/internal/cache/read_shard.go @@ -251,8 +251,8 @@ func (e *readEntry) waitForReadPermissionOrHandle( e.mu.Unlock() select { case <-ctx.Done(): - e.mu.Lock() - errorDuration = unlockAndUnrefAndTryRemoveFromMap(false) + e.mu.RLock() + errorDuration = unlockAndUnrefAndTryRemoveFromMap(true) return Handle{}, errorDuration, ctx.Err() case _, ok := <-ch: if !ok { @@ -344,6 +344,9 @@ func (e *readEntry) setReadValue(v *Value) Handle { e.mu.Lock() // Acquire a ref for readEntry, since we are going to remember it in e.mu.v. v.acquire() + if e.mu.v != nil { + panic("value already set") + } e.mu.v = v if !e.mu.isReading { panic("isReading is false")