Browser clock clamping exposed a gem ID collision bug hidden from JVM for months
A developer building a match-3 game discovered that the same Java source code produced 301 duplicate gem IDs in the browser but zero on the JVM across 128,000 gems. The root cause was reliance on System.nanoTime() for ID generation, which works reliably on the JVM but fails in browsers because Spectre mitigations clamp the clock to roughly 100-microsecond resolution. Running identical logic on two runtimes — the JVM and TeaVM-compiled JavaScript — acted as a free cross-check that surfaced the discrepancy without requiring the developer to anticipate the failure. The fix replaced the timestamp-and-random scheme with a simple atomic counter, eliminating any dependency on platform clock resolution. Three regression tests were added to CI to ensure gem IDs can never silently revert to clock-dependent generation.
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