Skip to content

fix(ext/node): send http2 GOAWAY before stream RSTs so peer sees session destroy code - #33637

Merged
littledivy merged 1 commit into
denoland:mainfrom
divybot:claude/test-http2-propagate-session-destroy-code
Apr 29, 2026
Merged

littledivy merged 1 commit into
denoland:mainfrom
divybot:claude/test-http2-propagate-session-destroy-code

Conversation

@divybot

@divybot divybot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables test-http2-propagate-session-destroy-code in node_compat suite.

Test plan

  • cargo test --test node_compat -- test-http2-propagate-session-destroy-code

…ion destroy code

Enables tests/node_compat/runner/suite/test/parallel/test-http2-propagate-session-destroy-code.js

Co-authored-by: Divy Srivastava <me@littledivy.com>

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Verified the fix logic:

The reordering moves the GOAWAY-submit-and-drain block from after state.streams.forEach(stream => stream.destroy(error)) to before it, so the wire order becomes:

  1. handle.goaway(code, 0) queues a GOAWAY frame with the session-level error code (e.g. NGHTTP2_REFUSED_STREAM = 7).
  2. The synchronous while (!socket.destroyed) { socket.write(handle.getOutgoingChunk()) } flushes the GOAWAY to the wire.
  3. state.streams.forEach(stream => stream.destroy(error)) then queues per-stream RST_STREAM frames and drains them.

That ordering matters for the upstream test: when the peer receives GOAWAY first, it sets session[kSession].goawayCode = 7 before the per-stream RST_STREAM arrives, so the peer's stream destroy path picks up the session-level error and surfaces "Session closed with error code 7" (matching the test's errRegEx = /Session closed with error code 7/). Without the reorder, RST_STREAM lands first, the peer's stream goes to ERR_HTTP2_STREAM_ERROR, and session.goawayCode is still null at that point — the propagation test fails.

Other things I checked:

  • Skip conditions preserved: typeof code === "number" && (state.flags & SESSION_FLAGS_CLOSED) === 0 && socket && !socket.destroyed && typeof handle.goaway === "function" — same five conditions as before, just moved. The graceful-close path (session.close() → SESSION_FLAGS_CLOSED set → submitGoaway already done) and the destroy(null) re-entry from kMaybeDestroy both correctly skip this block. ✓
  • Drain-loop termination: the while breaks on !chunk || chunk.byteLength === 0. After a GOAWAY frame is submitted there's no further frame production from this side, so getOutgoingChunk() returns empty within a small bounded number of iterations. ✓
  • Stream destroy still drains its own RSTs synchronously: per-stream submitRstStream + scheduleSendPending runs after this block, so RST_STREAM frames still hit the wire (just behind the GOAWAY). ✓
  • Test enrollment alphabetically positioned: test-http2-priority-event < test-http2-propagate-session-destroy-code < test-http2-raw-headers-defaults. ✓

CI fully green: 133 SUCCESS, 0 FAILURE, 2 SKIPPED. All 36 test node_compat shards (3 × 6 platforms × debug+release) pass, all 12 test unit_node shards pass.

@littledivy littledivy left a comment

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.

LGTM

@littledivy
littledivy merged commit c3b3936 into denoland:main Apr 29, 2026
136 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants