C++ Cache Bug: Duplicate Expiry Timestamps Can Silently Erase Map Entries
A subtle bug in C++ std::map usage can cause live cache entries to be silently dropped when two keys share the same expiry timestamp. The issue arises when a custom comparator relies solely on expiry time for ordering, violating the strict weak ordering requirement if no tiebreaker is included. When two entries share an identical expiry second, the map treats them as the same key, causing one to overwrite or disappear entirely. The recommended fix is to separate identity from eviction policy — use a plain map keyed by ID and manage expiry through a separate heap or scan. Developers are advised to always test comparators with forced timestamp collisions and enable sanitizers rather than relying on incidental timing differences to mask the flaw.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in