Urgent.News

What's breaking now, across thousands of outlets.

Tech

The Map Dropped a Key When Two Expiry Times Matched

A C++ map can drop a live cache entry. One <= in a comparator is enough. I forced a timestamp tie and watched a key vanish. Would you have caught that in review? This is a debugging retrospective. It is not a product tour. The artifact is a comparator audit you can run locally. The symptom I reconstructed a small TTL cache. Insert looked fine. Lookup looked fine. Unit tests stayed green. Then two…

A C++ map can drop a live cache entry when two entries share the same expiry time. One key vanished without any exceptions or log messages. The issue lies in the comparator used to order the map. Initially, it was assumed that expiry values would never collide. However, when two entries had the same expiry second, the comparator failed to distinguish between them, treating distinct ids as equivalent.

This led to the second insert being dropped or the tree going "sick" without a crash. The root cause is that std::map requires a strict weak ordering, and comp(x, x) must be false. When equal expiry is used with this comparator, distinct ids become equivalent, causing the bug. The fix is to use a total order on identity and use expiry only as data.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A New Approach to Form Data Handling in CodeBehind 4.7

CodeBehind 4.7 introduces an important improvement to the way Form data is handled in incoming requests. From this version onward, Form data should no longer be accessed directly through…

  • CodeBehind 4.7 alters Form data handling in requests.
  • HasFormContentType method verifies Form data structure.
  • IfForm extension simplifies conditional Form data access.

More from Saturday 5 September →