{"slug": "when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug", "title": "When \"idle\" isn't idle: how a Linux kernel optimization became a QUIC bug", "summary": "The article describes a bug in Cloudflare's QUIC implementation (quiche) where the CUBIC congestion control algorithm's congestion window (cwnd) becomes permanently stuck at its minimum value after a period of heavy packet loss, preventing recovery. The bug was triggered by porting a Linux kernel optimization from RFC 9438 to QUIC, causing approximately 60% of integration tests to fail when 30% random packet loss was applied during the first two seconds of a connection. The issue was resolved with a simple, near-one-line code fix that broke the cycle of the cwnd remaining pinned at its minimum.", "body_md": "CUBIC, standardized in __RFC 9438__, is the default congestion controller in Linux, and as a result governs how most TCP and QUIC connections on the public Internet probe for available bandwidth, back off when they detect loss, and recover afterward. At Cloudflare, our open-source implementation of QUIC,[ ](https://github.com/cloudflare/quiche)__quiche__, uses CUBIC as its default congestion controller, meaning this code is in the critical path for a significant share of the traffic we serve.\n\nIn this post, we’ll tell the story of a bug in which CUBIC's congestion window (cwnd) gets permanently pinned at its minimum and never recovers from a congestion collapse event.\n\nThe story starts with a __Linux kernel change__ aimed at bringing CUBIC into line with the app-limited exclusion described in __RFC 9438 §4.2-12__ — a fix to a real problem in TCP that, when ported to our QUIC implementation, surfaced unexpected behaviors in quiche. It has a happy ending: an elegant (near-)one-line fix that broke the cycle.\n\n## CUBIC's logic in a nutshell\n\nBefore we dive into the core problem, a quick refresher on Congestion Control Algorithms (CCAs) may help to set the stage.\n\nThe central knob a CCA turns is the **congestion window** (`cwnd`\n\n): the sender-side cap on how many bytes can be in flight (sent but not yet acknowledged) at any moment. A larger `cwnd`\n\nlets the sender push more data per round trip; a smaller `cwnd`\n\nthrottles it. Every loss-based CCA, CUBIC included, is ultimately a policy for how to grow `cwnd`\n\nwhen the network looks healthy and how to shrink it when it doesn't.\n\nIn essence, CCAs aim to maximize data transfer by inferring the \"available bandwidth\" of the network; because no one wants to pay for a 1 Gbps subscription and only use a fraction of it. The family of loss-based algorithms, to which CUBIC belongs, operate on a fundamental premise: (1) if there is no packet loss, increase the sending rate (i.e. increase the bandwidth utilization); (2) if there is loss, loss-based algorithms assume that the network's capacity has been exceeded, and the sender must back off (i.e. decrease the bandwidth utilization).\n\nThis logic is built on several assumptions that have been revisited over the years. However, we'll save that discussion for another time.\n\n## The symptom: a test that fails 61% of the time\n\nOur investigation started with the report of unexpected failures in our ingress proxy integration test pipeline. This erratic behavior appeared in tests where CUBIC was evaluated in a scenario of heavy loss in the early part of the connection.\n\nRecovery after congestion collapse is an uncommon regime, but it is exactly the regime a congestion controller exists to handle. Most congestion control tests exercise the steady-state and growth phases of an algorithm; far fewer probe what happens at minimum cwnd, after the connection has been beaten down. Bugs in this corner of the state space are invisible in throughput dashboards, undetectable by static review, and only surface when you deliberately drive a CCA into it and watch whether it can climb back out — which is exactly what this test did.\n\nThe simulated test setup includes the following details:\n\nQuiche HTTP/3 client and server running at locally (localhost)\n\nRTT = 10ms (set up in the configuration)\n\nA 10 MB file download over HTTP/3\n\nUsing CUBIC congestion control\n\nWith 30% random packet loss injected during the first two seconds\n\nAfter two seconds, loss stops entirely\n\nThe test has a generous 10-second timeout to complete the download, which is expected to be completed in four or five seconds\n\nThe expected behavior is straightforward: CUBIC should take some hits during the loss phase, reduce its congestion window, and once loss stops, steadily ramp up and finish the download well within the timeout. Instead, we observed in multiple 100-time runs that around 60% of our tests were not able to complete the download within the generous 10-second timeout.\n\n## The anomaly: 999 state transitions with zero loss\n\nWe instrumented[ ](https://github.com/cloudflare/quiche)__quiche's qlog__ output with packet loss events and built visualizations to understand what was happening inside the congestion controller:\n\n*Connection overview of a failing test. After T=2s, packet loss stops entirely — yet cwnd remains pinned at the minimum floor and the congestion state oscillates between recovery and congestion avoidance every ~14ms.*\n\nAfter the two-second (2000 ms) mark, packet loss stops entirely. However, the number of bytes in flight remains flat, which contradicts the core logic of the CUBIC algorithm: in the absence of loss, apply more gas to increase throttle (more bytes in our world). *This raises the question: if the network is no longer dropping packets, why is the congestion window failing to grow?*\n\nWhen we zoom into that region, our analysis shows that CUBIC enters a rapid oscillation, shown in our plot as an extended recovery phase, between congestion avoidance state (the operational regime phase) and recovery state (the packet loss recovery state) — 999 transitions in approximately 6.7 seconds. That’s one transition every ~14ms — suspiciously close to the connection's RTT (10ms). Throughout this entire period, cwnd is locked at the minimum floor: 2700 bytes, or two full-size packets.\n\nClearly something in CUBIC's logic is misinterpreting the state of the connection. The key clue is the oscillation period: ~14ms matches the RTT. Whatever is triggering the recovery/avoidance flip is happening once per round trip, in lockstep with connection's ACK clock; the self-clocking rhythm in which each round-trip's ACKs from the client trigger the server's next send. Because this is a download (server to client), the ACKs in question travel client to server, and CUBIC's state machine runs on the server side: every time those ACKs land, bytes_in_flight drops to zero and the server sends the next two-packet burst, which is what triggers the bug.\n\nTo confirm this behavior was CUBIC-specific, we ran the same test with __Reno__, another member of the loss-based family but with a different growth rate. The results were conclusive: 100% pass rate, showing Reno recovered cleanly after the loss phase, and revealing that this is a CUBIC-related bug.\n\n*Reno recovers cleanly after the loss phase ends at T=2s and completes the download by ~5s*\n\nLoss-based algorithms have two pedals, gas and brake, with a difference in how they accelerate. Well, CUBIC comes with some extra features. Here we are going to focus on bytes_in_flight == 0.\n\n### TCP CUBIC after idle (Linux, 2017)\n\nTo understand the bug, we first need to understand the optimization it came from. In 2017,an issue was found with Linux kernel's CUBIC implementation. The[ ](https://github.com/torvalds/linux/commit/30927520dbae297182990bb21d08762bcc35ce1d)__commit message__ explains:\n\nThe epoch is only updated/reset initially and when experiencing losses. The delta \"t\" of `now - epoch_start`\n\ncan be arbitrary large after app idle as well as the `bic_target`\n\n. Consequentially the slope (inverse of `ca->cnt`\n\n) would be really large, and eventually `ca->cnt`\n\nwould be lower-bounded in the end to 2 to have delayed-ACK slow-start behavior.\n\nThis particularly shows up when `slow_start_after_idle`\n\nis disabled as a dangerous cwnd inflation (1.5 x RTT) after few seconds of idle time.\n\nThe **epoch** is the reference timestamp CUBIC uses to anchor its growth curve: `W_cubic(delta_t)`\n\nis parameterized by `delta_t = now - epoch_start`\n\n, and the epoch is reset whenever CUBIC restarts its growth function — most notably after a loss event reduces `cwnd`\n\n. Between resets, `delta_t`\n\ngrows monotonically with wall-clock time.\n\nWhen an application goes idle (stops sending) for a while and then resumes, the CUBIC growth function `W_cubic(delta_t)`\n\ncomputes `delta_t`\n\nas `now - epoch_start`\n\n, as illustrated in the figure below. Since the epoch wasn't updated during idle, `delta_t`\n\nis huge, producing an enormous target window — and CUBIC would immediately try to inflate `cwnd`\n\nto an unreasonable value.\n\nJana Iyengar's initial fix was to reset `epoch_start` when the application resumes sending. But Neal Cardwell __pointed out__ the flaw in that approach:\n\n…it would ask the CUBIC algorithm to recalculate the curve so that we again start growing steeply upward from where cwnd is now (as CUBIC does just after a loss). Ideally we'd want the cwnd growth curve to be the same shape, just shifted later in time by the amount of the idle period.\n\nThe elegant solution, authored by Eric Dumazet, Yuchung Cheng, and Neal Cardwell, was to shift the epoch forward by the idle duration rather than resetting it. This preserves the shape of the CUBIC growth curve — just sliding it in time so that the algorithm picks up where it left off.\n\n### The port to quiche (2020)\n\nWhen CUBIC was __first implemented__ in quiche, this idle-period adjustment was ported. However, QUIC, which runs in the user space, doesn't have TCP's kernel-level __CA_EVENT_TX_START__\n\ncallback. Instead, the quiche implementation checks for the idle condition inside `on_packet_sent()`\n\n:\n\n```\n// cubic.rs — on_packet_sent() (simplified)\n/// Updates the state when a packet is sent.\nfn on_packet_sent(&mut self, bytes_in_flight: usize, now: Instant, ...) {\n    // If the sending burst is restarting (i.e., bytes_in_flight was zero before this send),\n    // adjust the congestion recovery start time to account for the gap in sending.\n    if bytes_in_flight == 0 {\n        let delta = now - self.last_sent_time;\n        self.congestion_recovery_start_time += delta;\n    }\n    // Record the time of this send event.\n    self.last_sent_time = now;\n}\n```\n\n### Where it breaks: the QUIC difference\n\nThe fix ported to quiche included a bug in the original kernel change which was fixed by a __followup change to the kernel cubic module__ about a week later. The commit message for the second fix explains:\n\n`tcp_cubic`\n\n: do not set `epoch_start`\n\nin the future\nTracking idle time in `bictcp_cwnd_event()`\n\nis imprecise, as `epoch_start`\n\nis normally set at ACK processing time, not at send time.\n\nDoing a proper fix would need to add an additional state variable,\nand does not seem worth the trouble, given CUBIC bug has been there\nforever before Jana noticed it.\n\nLet's simply not set `epoch_start`\n\nin the future, otherwise\n`bictcp_update()`\n\ncould overflow and CUBIC would again\ngrow `cwnd`\n\ntoo fast.\n\nAs mentioned in the commit message, recovery start time is set during ACK processing, and the computation of the adjustment based on sent times can push the recovery start time into the future. This explains the oscillation between recovery and congestion avoidance seen on our test. The trap only consistently triggers when every incoming ACK drives bytes_in_flight all the way to zero — which in practice means cwnd has collapsed to its minimum (two packets) and the application has data ready to send another full window the moment an ACK arrives. Outside this regime, bytes_in_flight == 0 is less likely to hold on every send, so it is less likely to trigger the bug.\n\nWhy doesn't this also happen at connection start? The bug only triggers when the connection exits slow-start and switches over to congestion avoidance. Before exiting slow-start, `congestion_recovery_start_time`\n\nis not set, so the buggy branch in `on_packet_sent`\n\nhas no recovery boundary to advance. During slow start CUBIC's `cwnd`\n\ngrows by the same Reno-style ack-based rule shared by all loss-based CCAs — the cubic curve and its sensitivity to `congestion_recovery_start_time`\n\nonly enter the picture once the connection is in congestion avoidance, meaning the trap needs three things at once: a real loss event to set the recovery boundary, congestion avoidance to be running, and `cwnd`\n\ncollapsed to the two-packet floor.\n\n*The self-perpetuating recovery trap. At minimum cwnd, every ACK cycle triggers the idle period adjustment with an inflated delta.*\n\nAt a minimum cwnd (two packets), the dynamics of the connection shift into a \"death spiral\" where the idle period optimization becomes a self-fulfilling prophecy. This trap operates in a continuous loop:\n\n**Send and ACK packets: **The sender transmits the entire two-packet window. After one RTT (~14ms), both packets are ACKed, causing bytes_in_flight to drop to zero.\n\n**False idle detection:** When the next burst is sent, on_packet_sent() sees bytes_in_flight == 0 and assumes the connection was idle, but it was congestion limited.\n\n**Inflated delta:** The calculation uses now - last_sent_time to determine the idle duration. When the congestion window (`cwnd`\n\n) is at its minimum, `last_sent_time`\n\nis the timestamp of the *start* of the previous RTT cycle. Therefore, the resulting delta is approximately 14ms (the connection's RTT + additional rounding errors). This RTT-sized delta is incorrectly applied as the \"idle\" time. The *actual* time the connection was idle (the processing gap between the last ACK arriving and the next packet being sent) is effectively 0. By measuring the full RTT instead of the true gap, the delta is inflated significantly, aggressively shifting the recovery start time forward, possibly into the future.\n\n**Perceived recovery:** Because the recovery start time is now in the future, the `in_congestion_recovery()`\n\ncheck returns true for every incoming ACK. Processing of the next ACK exits recovery and sets the recovery start to the ACK time which is larger than last_sent_time, making it likely for the congestion controller to push the recovery time into the future when doing the next send.\n\n**Stagnation:** Since CUBIC skips `cwnd`\n\ngrowth for any packet perceived to be in a recovery period, the window remains pinned at two packets — ensuring the pipe drains completely on the next ACK and restarting the cycle.\n\nAnd this loop repeats for thousands of cycles until the accumulation of small deviations — from scheduler jitter and ACK processing variance — lets the <= boundary in `in_congestion_recovery()`\n\nslip behind the next packet's send time, breaking the cycle.\n\n## The fix: measuring idle from the right moment\n\nFixing the death spiral involves measuring the idle duration from when bytes_in_flight actually transitioned to zero (the last ACK processed) rather than the last packet sent.\n\nAdd last_ack_time timestamp to the CUBIC state.\n\nUpdate that timestamp when ACKs arrive.\n\nUse it for the idle delta computation:\n\n```\n// cubic.rs — on_packet_sent()\nfn on_packet_sent(&mut self, bytes_in_flight: usize, now: Instant, ...) {\n    // Check if the connection was idle before this packet was sent.\n    if bytes_in_flight == 0 {\n        if let Some(recovery_start_time) = r.congestion_recovery_start_time {\n            // Measure idle from the most recent activity: either the\n            // last ACK (approximating when bif hit 0) or the last data\n            // send, whichever is later. Using last_sent_time alone\n            // would inflate the delta by a full RTT when cwnd is small\n            // and bif transiently hits 0 between ACK and send.\n            let idle_start = cmp::max(cubic.last_ack_time, cubic.last_sent_time);\n\n            if let Some(idle_start) = idle_start {\n                if idle_start < now {\n                    let delta = now - idle_start;\n                    r.congestion_recovery_start_time =\n                        Some(recovery_start_time + delta);\n                }\n            }\n        }\n}\n```\n\nWith the delta now reflecting the actual gap since the last ACK, the recovery boundary stops chasing the send time:\n\n*Old code: boundary advances one RTT per cycle, always landing on or ahead of the next send.*\n\n*Fix: boundary barely moves; the next send lands ahead of it and cwnd grows.*\n\nFor genuinely idle connections, `last_ack_time`\n\nis far in the past and the same expression captures the full idle duration, the original epoch-shift behavior is preserved.\n\nWith the fix applied, the 100% pass rate of our quiche testing suite was restored.\n\n*After the fix, cwnd grows along the expected CUBIC curve and the download completes in ~4-5 seconds.*\n\nWe don't worry about the losses at the end of the connection — that's expected because we fully utilized the router's allocated buffer. In other words, we are fully utilizing the available bandwidth in this test case.\n\n**\"Idle\" is harder to define than it sounds.** Normal pipeline delays at small windows can look like idleness to simple checks.\n\n**Minimum-cwnd dynamics are a unique corner case.** The bug was invisible at high speeds and only triggered after severe loss.\n\n**The fix was surprisingly small compared to the complexity of the behavior.** After weeks of instrumenting qlogs and analyzing visualizations to find the root cause, the solution required changing just three lines of code. As we noted during the investigation: the effort to find the bug was massive, but the fix itself was basically one line of logic.\n\nThe fix described in this post has been contributed to __cloudflare/quiche__\n\n, Cloudflare's open-source implementation of QUIC and HTTP/3. Our CCA efforts go beyond loss-based algorithms: we also use quiche’s modular congestion control design to experiment with and tune our model-based __BBRv3__ implementation, now enabled for a growing percentage of our QUIC deployments. Stay tuned for further updates on QUIC congestion control implementation and performance.\n\nIf you're interested in congestion control, transport protocols, or contributing to open-source networking code, check out the **quiche** repository. We're always looking for talented engineers who love digging into problems like these, please explore our[ ](https://www.cloudflare.com/careers/)__open positions__.", "url": "https://wpnews.pro/news/when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug", "canonical_source": "https://blog.cloudflare.com/quic-death-spiral-fix/", "published_at": "2026-05-12 13:00:00+00:00", "updated_at": "2026-05-24 03:08:04.231604+00:00", "lang": "en", "topics": ["open-source", "cloud-computing", "research"], "entities": ["CUBIC", "Linux", "QUIC", "Cloudflare", "quiche", "RFC 9438"], "alternates": {"html": "https://wpnews.pro/news/when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug", "markdown": "https://wpnews.pro/news/when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug.md", "text": "https://wpnews.pro/news/when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug.txt", "jsonld": "https://wpnews.pro/news/when-idle-isn-t-idle-how-a-linux-kernel-optimization-became-a-quic-bug.jsonld"}}