Skip to content

Bump undici & TS #9847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Bump undici & TS #9847

wants to merge 10 commits into from

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Jul 3, 2025

Bump Undici & TS to the latest versions. I had a quick read of the Undici v6 & v7 breaking changes, and nothing seems like it'll affect us, but I'm mostly relying on E2E test coverage here, and the fact that we use the fetch() API which shouldn't have changed.


  • Tests
    • Tests included
    • Tests not necessary because: covered by existing tests
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal change
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: this has no user-facing changes in wrangler

Copy link

changeset-bot bot commented Jul 3, 2025

🦋 Changeset detected

Latest commit: 0d4bd70

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
miniflare Patch
wrangler Patch
@cloudflare/pages-shared Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@penalosa penalosa force-pushed the penalosa/bump-undici branch 2 times, most recently from 3349d58 to 4b37b39 Compare July 3, 2025 23:51
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jul 3, 2025
Copy link

pkg-pr-new bot commented Jul 3, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@9847

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@9847

miniflare

npm i https://pkg.pr.new/miniflare@9847

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@9847

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@9847

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@9847

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@9847

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@9847

wrangler

npm i https://pkg.pr.new/wrangler@9847

commit: 0d4bd70

@penalosa penalosa force-pushed the penalosa/bump-undici branch from 859a957 to d5593a9 Compare July 4, 2025 13:18
@penalosa penalosa marked this pull request as ready for review July 4, 2025 13:24
@penalosa penalosa requested review from a team as code owners July 4, 2025 13:24
let protocols: string[] | undefined;
for (const [key, value] of request.headers.entries()) {
if (key.toLowerCase() === "sec-websocket-protocol") {
protocols = value.split(",").map((protocol) => protocol.trim());
} else {
headers[key] = value;
headers.set(key, value);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Would it be better to make it headers.append(key, value)? As there could be multiple entries with the same key.

@@ -59,13 +52,13 @@ export async function fetch(
// Establish web socket connection
const ws = new NodeWebSocket(url, protocols, {
followRedirects: request.redirect === "follow",
headers,
headers: Object.fromEntries(headers.entries()),
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Object.fromEntries will ignores repeated keys, how about new undici.Headers(headers)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will, but this is being passed in to WebSocket from ws, which only accepts an object here.

Comment on lines +24 to +25
const requests = new Map<string, BufferedRequest>();
const responses = new Map<string, Response>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, we relied on stability of the DispatchOptions variable, but that is no longer guaranteed in Undici v7 (see https://github.com/nodejs/undici/blob/c6a8b23ee55b34fedd7b90d3c7f4b51a35d3ee25/lib/mock/mock-agent.js#L74). As such, we serialise the options for lookup, and make sure we remove them manually from the Map after access so as not to cause a memory leak.

Comment on lines -119 to -123
onConnect(abort) {
if (abortSignalAborted) {
abort();
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't appear to work in Undici v7. The abort() parameter isn't documented so I'm not 100% sure, but in manual testing calling abort() here (rather than in onComplete) causes fetch() calls to abort with undefined

@penalosa penalosa added the skip-v3-pr Skip validation of presence of a v3 backport PR label Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-v3-pr Skip validation of presence of a v3 backport PR
Projects
Status: Untriaged
Development

Successfully merging this pull request may close these issues.

2 participants