Skip to content

Conversation

@gcloudream
Copy link

@gcloudream gcloudream commented Jan 13, 2026

Problem

Using extremely large TTLs (e.g., Long.MAX_VALUE or values that saturate to it) can break expiration scheduling. The code computes expectedExpiration = now + duration in nanoseconds. With a huge duration this overflows to a negative value, making that entry look like the earliest expiration. The scheduler then computes expectedExpiration - now, which underflows to a massive positive delay (~292 years). Because ExpiringMap schedules one entry at a time, short TTL entries stop expiring.

Fix

  • Use saturating addition when computing expectedExpiration to avoid overflow.
  • Treat Long.MAX_VALUE as "no expiration" and skip scheduling such entries.
  • Clamp delay when already due to avoid negative/overflow delays.

Tests

  • Added Issue93 regression test to ensure a very long TTL does not block short TTL expirations.

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