Skip to content

http2: fix async context loss when trailers carry END_STREAM - #63814

Open
orgads wants to merge 1 commit into
nodejs:mainfrom
orgads:http2-async-trailers
Open

http2: fix async context loss when trailers carry END_STREAM#63814
orgads wants to merge 1 commit into
nodejs:mainfrom
orgads:http2-async-trailers

Conversation

@orgads

@orgads orgads commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The previous fix (f67e45e) wrapped header/response event dispatch in reqAsync.runInAsyncScope(), but missed the stream.push(null) call that triggers the 'end' event. When END_STREAM arrives on a trailing HEADERS frame (as gRPC does), the 'end' event fires in the session's async context instead of the request's context.

Wrap the stream.push(null) at end-of-stream in reqAsync.runInAsyncScope() so that the 'end' event preserves the correct AsyncLocalStorage context.

Refs:

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. labels Jun 9, 2026
@orgads
orgads force-pushed the http2-async-trailers branch from 00f4171 to a39d251 Compare June 9, 2026 10:20
@orgads

orgads commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

The macOS failure looks unrelated to my change.

@Qard Qard added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

The previous fix (f67e45e) wrapped header/response event dispatch in
reqAsync.runInAsyncScope(), but missed the stream.push(null) call that
triggers the 'end' event. When END_STREAM arrives on a trailing HEADERS
frame (as gRPC does), the 'end' event fires in the session's async
context instead of the request's context.

Wrap stream.push(null) at end-of-stream in reqAsync.runInAsyncScope()
so that the 'end' event preserves the correct AsyncLocalStorage context.

Refs: nodejs#55460
Signed-off-by: Orgad Shaneh <orgad.shaneh@audiocodes.com>
@orgads
orgads force-pushed the http2-async-trailers branch from a39d251 to 559fba0 Compare August 1, 2026 18:39

@mcollina mcollina 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

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 1, 2026
@github-actions github-actions Bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor
Failed to start CI
- Validating Jenkins credentials
✔  Jenkins credentials valid
- Querying data for job/node-test-pull-request/74093/
[SyntaxError: Unexpected token '<', ..."    
  https://github.com/nodejs/node/actions/runs/30714978721

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (a4aa3c0) to head (559fba0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #63814   +/-   ##
=======================================
  Coverage   90.28%   90.29%           
=======================================
  Files         760      760           
  Lines      247061   247065    +4     
  Branches    46592    46587    -5     
=======================================
+ Hits       223058   223080   +22     
+ Misses      15491    15444   -47     
- Partials     8512     8541   +29     
Files with missing lines Coverage Δ
lib/internal/http2/core.js 95.07% <100.00%> (+<0.01%) ⬆️

... and 35 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.

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

Labels

http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants