Skip to content

fix: prevent oversized entries from retaining buffers - #435

Open
G4RASU wants to merge 1 commit into
allegro:mainfrom
G4RASU:fix-entry-buffer-retention
Open

fix: prevent oversized entries from retaining buffers#435
G4RASU wants to merge 1 commit into
allegro:mainfrom
G4RASU:fix-entry-buffer-retention

Conversation

@G4RASU

@G4RASU G4RASU commented Sep 8, 2026

Copy link
Copy Markdown

cacheShard.set and cacheShard.append build the wrapped entry in entryBuffer before pushing it into the shard's entries queue.

When the final entry is larger than the shard's maximum capacity, BytesQueue.Push eventually rejects it. However, the entry has already caused entryBuffer to grow, and the failed push path may also evict existing entries before returning the error.

This causes unnecessary memory retention and can remove valid cached entries even though the new entry cannot be stored.

This change adds a non-mutating BytesQueue.CanFit check before using entryBuffer:

  • Set checks the encoded entry size before wrapping it.
  • Append checks the final size of the existing entry plus the new data.
  • Oversized entries return ErrEntryTooBig immediately.
  • The queue and existing cache entries remain unchanged when the entry cannot fit.

Adds regression tests covering oversized Set and Append operations, verifying that neither entryBuffer nor the queue grows and that existing entries are preserved.

go test ./... passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant