From 043f78a74f18d80d95e0f6d04f847db29ee8d96a Mon Sep 17 00:00:00 2001 From: "xinyang.nan" Date: Fri, 15 Apr 2022 18:26:12 +0800 Subject: [PATCH] Fix subtractive overflow --- shard.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shard.go b/shard.go index 37b09522..ee6ee25e 100644 --- a/shard.go +++ b/shard.go @@ -269,7 +269,10 @@ func (s *cacheShard) del(hashedKey uint64) error { func (s *cacheShard) onEvict(oldestEntry []byte, currentTimestamp uint64, evict func(reason RemoveReason) error) bool { oldestTimestamp := readTimestampFromEntry(oldestEntry) - if currentTimestamp-oldestTimestamp > s.lifeWindow { + keyHash := readHashFromEntry(oldestEntry) + if keyHash == 0 || (currentTimestamp >= oldestTimestamp && + currentTimestamp-oldestTimestamp > s.lifeWindow) { + evict(Expired) return true }