Skip to content

quic: fix edge cases where stream FIN would be lost - #66759

Open
pimterry wants to merge 1 commit into
nodejs:mainfrom
pimterry:fix-stream-flush-flake
Open

pimterry wants to merge 1 commit into
nodejs:mainfrom
pimterry:fix-stream-flush-flake

Conversation

@pimterry

Copy link
Copy Markdown
Member

I found that test-quic-flow-control-concurrent-volume failed on my machine under load while doing some other QUIC dev, did some digging, and it turns out it's a real bug. Flow:

  • A stream ends, and an empty FIN frame needs to be sent.
  • When sending it, ngtcp2 doesn't have space in the packet due to other data (ACKs, retransmissions, the rest of the stream data, etc) so ngtcp2_conn_writev_stream sets nwrite > 0 (a packet was produced) but ndatalen == -1 (this stream's data wasn't included).
  • Because a packet was produced, we skip the existing nwrite == 0 case which reschedules streams to try again later. This applies for data not sent due to congestion, but not data omitted due to packet space.
  • For frames containing data, this doesn't matter, as they're always rescheduled for later here.
  • Empty FIN has no data though - so the stream is never rescheduled, the FIN is lost, and from peer's POV stream never ends.

The fix here works by rescheduling the stream in all cases where the frame couldn't be included (ndatalen < 0) and there was no error (nwrite >= 0), not just congestion. The early exit below for nwrite == 0 remains, since we do still need to stop once we hit congestion regardless. Simplified the comment to explain this more clearly en route.

Reproduced in a standalone test here, which triggers this by sending a STREAM frame + FIN frame where the data is large enough that the FIN doesn't fit. The exact size to trigger this can vary, so this runs a full sweep over message sizes from 1000 - 1300, and makes sure they all deliver successfully (including clean FIN). Fails reliably on main, passes with this change. The original flaky test also no longer flakes 😄.

Signed-off-by: Tim Perry <pimterry@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/quic

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation. labels Oct 15, 2026
@pimterry pimterry moved this to Ready for Review in QUIC Team Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (12ce819) to head (9daf646).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66759      +/-   ##
==========================================
+ Coverage   90.48%   90.50%   +0.02%     
==========================================
  Files         797      797              
  Lines      277491   277503      +12     
  Branches    53318    53322       +4     
==========================================
+ Hits       251091   251161      +70     
+ Misses      16793    16752      -41     
+ Partials     9607     9590      -17     

see 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/quic/session.cc
Comment on lines -2093 to -2094
// We call Application::ResumeStream directly (not Session::ResumeStream)
// to avoid creating a SendPendingDataScope — we're already inside

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this part still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation.

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants