Skip to content

Commit d77b99c

Browse files
AchoArnoldCopilot
andcommitted
fix: flush ristretto buffer before cache.Del to prevent async Set race
Ristretto's Set operations are buffered asynchronously. If a prior request's SetWithTTL is still in the buffer when Del runs, Del finds nothing to remove, and the buffered Set then re-adds the entry — causing the old key to remain valid. Adding cache.Wait() before cache.Del() flushes all pending buffered operations first, ensuring the subsequent Del actually removes the cached entry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 50b3311 commit d77b99c

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

api/pkg/repositories/gorm_user_repository.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ func (repository *gormUserRepository) RotateAPIKey(ctx context.Context, userID e
8484
}
8585

8686
if err == nil && oldAPIKey != "" {
87+
// Wait() flushes any pending buffered Set operations in ristretto
88+
// before Del, preventing a race where a prior request's async Set
89+
// re-adds the key after our Del removes it from the store.
90+
repository.cache.Wait()
8791
repository.cache.Del(oldAPIKey)
8892
}
8993

0 commit comments

Comments
 (0)