Skip to content

Commit

Permalink
fix: GetValue should set Updating=false to prevent items from droppin…
Browse files Browse the repository at this point in the history
…g out of revocation and refresh schedule
  • Loading branch information
mahe-work committed Oct 26, 2021
1 parent 5721a1c commit 812def7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func GetValue(key string) []byte {
if ok {
item := value.(timedCacheItem)
item.UpdateRevokeTime()
item.Updating = false
cache.Set(item.Key, item)
return value.(timedCacheItem).Value
}
Expand Down
3 changes: 2 additions & 1 deletion cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestConcurrentRefreshAndGetValueBug(t *testing.T) {
loopInterval = defaultLoopInterval
}()
loopInterval = 10 * time.Millisecond
// Make sure revoke does not interfere here
StartWith(1, 11, 1, 5*time.Second)
// continuously spamming GetValue should manifest the bug
c := make(chan []byte, 1)
Expand Down Expand Up @@ -148,7 +149,7 @@ func TestConcurrentRevokeAndGetValueBug(t *testing.T) {
}()
loopInterval = 10 * time.Millisecond
StartWith(1, 11, 1, 20*time.Millisecond)
// Continuously spamming GetValue should force ConcurrentRefreshAndGetBug to manifest
// Continuously spamming GetValue should force ConcurrentRefreshAndGetBug to manifest if it is present
c := make(chan []byte, 1)
url := "https://httpbin.org/ip"
go busyGet(t, c, url)
Expand Down

0 comments on commit 812def7

Please sign in to comment.