GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: complete upgrade diagnostics lifecycle by BridgeAR · Pull Request #5761 · nodejs/undici

Conversation

@BridgeAR

@BridgeAR BridgeAR commented Sep 3, 2026

Copy link
Copy Markdown
Member

Successful CONNECT and protocol upgrades stop before Undici marks the request complete. Diagnostics subscribers retain per-request state, and streamed request-body listeners remain attached for the lifetime of the upgraded socket.

Complete accepted upgrades through the existing response-header and trailers events. Rejected and aborted upgrades retain the existing error terminal event.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina and dwinrick-lever reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@codecov-commenter

codecov-commenter commented Sep 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.50%. Comparing base (17117f6) to head (8a28e4f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5761      +/-   ##
==========================================
- Coverage   93.50%   93.50%   -0.01%     
==========================================
  Files         110      110              
  Lines       39072    39099      +27     
==========================================
+ Hits        36534    36558      +24     
- Misses       2538     2541       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR
BridgeAR marked this pull request as draft September 3, 2026 15:46
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-02-fix-request-upgrade-diagnostics branch from e674253 to 54a89bf Compare September 3, 2026 15:52
BridgeAR added a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests
5da6c72
Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761
@BridgeAR BridgeAR mentioned this pull request Sep 3, 2026
fix(undici): prevent context retention after requests DataDog/dd-trace-js#9406
Merged
@BridgeAR
fix: complete upgrade diagnostics lifecycle
6477ac7
Successful CONNECT and protocol upgrades stop before Undici marks the request complete. Diagnostics subscribers retain per-request state, and streamed request-body listeners remain attached for the lifetime of the upgraded socket.

Publish the existing headers and trailers lifecycle around accepted upgrades. Abort instead when the application upgrade handler throws so subscribers always receive a terminal event.

Signed-off-by: Ruben Bridgewater <[email protected]>
@BridgeAR
BridgeAR force-pushed the BridgeAR/2026-09-02-fix-request-upgrade-diagnostics branch from 54a89bf to 6477ac7 Compare September 3, 2026 16:08
BridgeAR added a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests
9acf1d8
Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761
@BridgeAR
fix: preserve upgrade handler errors
8a28e4f
Accepted upgrades run the user handler after H1 hands off its socket and H2 assigns stream cleanup. Request-level error handling replaced H1 exceptions and rethrew H2 exceptions outside their transport owners.
@mcollina

mcollina commented Sep 3, 2026

Copy link
Copy Markdown
Member

Do you need this backported to v7.x?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR added a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests
aaf8199
Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761
@BridgeAR
BridgeAR marked this pull request as ready for review September 3, 2026 18:35
@BridgeAR

BridgeAR commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

@mcollina yes, it needs to be backported to all supported release lines. It is an issue since v4.6.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Sep 3, 2026
[BUG]: undici plugin leaves finished span active in ALS after request (shared trace_id leak) DataDog/dd-trace-js#9387
Closed
[BUG]: express.middleware spans retained unbounded via AsyncLocalStorage frame capture → heap OOM DataDog/dd-trace-js#9227
Closed
bengl pushed a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests (#9406)
8283eb7
* fix(undici): prevent context retention after requests

Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761

* fix(undici): gate upgrade fallback by source

Released Undici versions omit terminal diagnostics for accepted upgrades, but patched and backported implementations can share those versions. Inspecting the loaded Request method avoids wrapping implementations that already publish terminal trailers.

* fix(undici): finish spans after upgrade handler errors

Accepted upgrade handlers can throw after Undici removes the request from its queue. Affected versions then destroy the socket without a terminal diagnostic event, which retains the span.

Publish one fallback error event and rethrow the original error. Scope the hook-context assertion to native diagnostics versions so Node 26 does not format unrelated cyclic span graphs.
dd-octo-sts Bot pushed a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests (#9406)
2b97e0e
* fix(undici): prevent context retention after requests

Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761

* fix(undici): gate upgrade fallback by source

Released Undici versions omit terminal diagnostics for accepted upgrades, but patched and backported implementations can share those versions. Inspecting the loaded Request method avoids wrapping implementations that already publish terminal trailers.

* fix(undici): finish spans after upgrade handler errors

Accepted upgrade handlers can throw after Undici removes the request from its queue. Affected versions then destroy the socket without a terminal diagnostic event, which retains the span.

Publish one fallback error event and rethrow the original error. Scope the hook-context assertion to native diagnostics versions so Node 26 does not format unrelated cyclic span graphs.
dd-octo-sts Bot pushed a commit to DataDog/dd-trace-js that referenced this pull request Sep 3, 2026
@BridgeAR
fix(undici): prevent context retention after requests (#9406)
80f4d9d
* fix(undici): prevent context retention after requests

Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761

* fix(undici): gate upgrade fallback by source

Released Undici versions omit terminal diagnostics for accepted upgrades, but patched and backported implementations can share those versions. Inspecting the loaded Request method avoids wrapping implementations that already publish terminal trailers.

* fix(undici): finish spans after upgrade handler errors

Accepted upgrade handlers can throw after Undici removes the request from its queue. Affected versions then destroy the socket without a terminal diagnostic event, which retains the span.

Publish one fallback error event and rethrow the original error. Scope the hook-context assertion to native diagnostics versions so Node 26 does not format unrelated cyclic span graphs.
@BridgeAR
BridgeAR requested review from a team, mcollina and trivikr and removed request for trivikr September 4, 2026 11:57
@mcollina

mcollina commented Sep 4, 2026

Copy link
Copy Markdown
Member

Can you open the backports PR then? The code would be substantially different in v7 at least.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Sep 4, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina
mcollina merged commit 95f6554 into main Sep 4, 2026
38 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mcollina
mcollina deleted the BridgeAR/2026-09-02-fix-request-upgrade-diagnostics branch September 4, 2026 16:08
BridgeAR added a commit to DataDog/dd-trace-js that referenced this pull request Sep 4, 2026
@BridgeAR
fix(undici): prevent context retention after requests (#9406)
00fb76d
* fix(undici): prevent context retention after requests

Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761

* fix(undici): gate upgrade fallback by source

Released Undici versions omit terminal diagnostics for accepted upgrades, but patched and backported implementations can share those versions. Inspecting the loaded Request method avoids wrapping implementations that already publish terminal trailers.

* fix(undici): finish spans after upgrade handler errors

Accepted upgrade handlers can throw after Undici removes the request from its queue. Affected versions then destroy the socket without a terminal diagnostic event, which retains the span.

Publish one fallback error event and rethrow the original error. Scope the hook-context assertion to native diagnostics versions so Node 26 does not format unrelated cyclic span graphs.
BridgeAR added a commit to DataDog/dd-trace-js that referenced this pull request Sep 4, 2026
@BridgeAR
fix(undici): prevent context retention after requests (#9406)
c85b5cd
* fix(undici): prevent context retention after requests

Native diagnostic callbacks entered request spans into the caller's async context. The context outlived finished requests, retained downstream resources, and made later work inherit the wrong span.

Keep native diagnostics for normal request lifecycles and instrument only Undici's accepted-upgrade callback, which has no terminal diagnostic event. Activate the request span only while a configured request hook runs.

The request-create hot path no longer copies the async store or switches context twice. In two fresh one-million-iteration runs it improved from 43.1-43.5 ns to 10.1-10.2 ns per operation.

Refs: nodejs/undici#5761

* fix(undici): gate upgrade fallback by source

Released Undici versions omit terminal diagnostics for accepted upgrades, but patched and backported implementations can share those versions. Inspecting the loaded Request method avoids wrapping implementations that already publish terminal trailers.

* fix(undici): finish spans after upgrade handler errors

Accepted upgrade handlers can throw after Undici removes the request from its queue. Affected versions then destroy the socket without a terminal diagnostic event, which retains the span.

Publish one fallback error event and rethrow the original error. Scope the hook-context assertion to native diagnostics versions so Node 26 does not format unrelated cyclic span graphs.
@kkennethlau12393 kkennethlau12393 mentioned this pull request Sep 6, 2026
chore: recreate nodejs/undici#5761 kkennethlau12393/nodejs__undici#1
Open
kkennethlau12393 pushed a commit to kkennethlau12393/nodejs__undici that referenced this pull request Sep 6, 2026
abloh-census
Revert "fix: complete upgrade diagnostics lifecycle (nodejs#5761)"
7d36e4f
This reverts commit 95f6554.
kkennethlau12393 pushed a commit to kkennethlau12393/nodejs__undici that referenced this pull request Sep 7, 2026
abloh-census
Revert "fix: complete upgrade diagnostics lifecycle (nodejs#5761)"
a9c4cc1
This reverts commit 95f6554.
@BridgeAR BridgeAR mentioned this pull request Sep 7, 2026
Backport upgrade diagnostics lifecycle fixes to v7.x #5783
Merged
3 of 7 tasks
@ronag ronag mentioned this pull request Sep 10, 2026
fix(upgrade): complete request lifecycle on handoff nxtedition/undici#90
Merged
@github-actions github-actions Bot mentioned this pull request Sep 14, 2026
[Release] v8.11.0 #5821
Closed
kkennethlau12393 pushed a commit to kkennethlau12393/nodejs__undici that referenced this pull request Sep 14, 2026
abloh-census
Revert "fix: complete upgrade diagnostics lifecycle (nodejs#5761)"
4c8170d
This reverts commit 95f6554.
kkennethlau12393 pushed a commit to kkennethlau12393/nodejs__undici that referenced this pull request Sep 14, 2026
abloh-census
Revert "fix: complete upgrade diagnostics lifecycle (nodejs#5761)"
45ad691
This reverts commit 95f6554.
kkennethlau12393 pushed a commit to kkennethlau12393/nodejs__undici that referenced this pull request Sep 15, 2026
abloh-census
Revert "fix: complete upgrade diagnostics lifecycle (nodejs#5761)"
ebf8c63
This reverts commit 95f6554.
This was referenced Sep 21, 2026
[Release] v8.11.0 #5848
Closed
[Release] v8.11.0 #5849
Merged
@mcollina mcollina mentioned this pull request Nov 13, 2026
fix(milo): port llhttp fixes and run CI with Milo #6206
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@trivikr trivikr Awaiting requested review from trivikr

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@BridgeAR @codecov-commenter @mcollina
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.