Skip to content

fix(cloud): preserve outbound WebSocket upgrades - #2601

Open
ulughbeck wants to merge 2 commits into
UsefulSoftwareCo:v2from
ulughbeck:fix/cloud-outbound-websocket
Open

ulughbeck wants to merge 2 commits into
UsefulSoftwareCo:v2from
ulughbeck:fix/cloud-outbound-websocket

Conversation

@ulughbeck

@ulughbeck ulughbeck commented Nov 26, 2026 •

Copy link
Copy Markdown

Summary

Cloud apps fail to open WebSocket connections to upstream services even when the upstream accepts the upgrade. The outbound gateway converts the upstream 101 Switching Protocols response with HttpServerResponse.fromWeb, which drops Cloudflare's Response.webSocket handle before the response reaches the app.

  • Return every native Response from the Cloud outbound gateway via HttpServerResponse.raw(response, { status: response.status, statusText: response.statusText }) so workerd keeps Response.webSocket attached and avoids re-wrapping outbound HTTP response bodies through Effect streams, while Effect's HttpServerResponse.toWeb still handles bodyless statuses (204/205/304/HEAD).
  • Exercise WebSocket echo (fetch upgrade, new WebSocket(...), and a credentialed upgrade) plus ordinary (202) and bodyless (204) HTTP responses from a deployed app on managed Cloud.

Verification

  • Local Cloud e2e passed for cloud-outbound-websocket.spec.ts (fetch 101 upgrade, new WebSocket(...), credentialed WebSocket upgrade, 202 HTTP, and 204 No Content), app-fetch-brotli.spec.ts, and app-egress-failures.spec.ts.
  • bun run e2e:outbound-routes passed.
  • bun run check passed all 19 checks.

CI test selection

e2e/tests/cloud-outbound-websocket.spec.ts
e2e/tests/app-egress-failures.spec.ts
e2e/tests/app-fetch-brotli.spec.ts
e2e/tests/concurrent-outbound.spec.ts
e2e/tests/credential-hosts.spec.ts

Release-note: Fix: Cloud apps can connect to upstream WebSocket services.
@ulughbeck ulughbeck changed the title Fix Cloud outbound WebSocket upgrades fix(cloud): preserve outbound WebSocket upgrades Nov 26, 2026
Instead of special-casing status 101, return every native Response from
the Cloud outbound gateway via HttpServerResponse.raw with its status
and statusText. This keeps workerd WebSocket upgrades attached, avoids
re-wrapping every outbound HTTP stream through Effect Stream, and lets
Effect's HttpServerResponse.toWeb handle bodyless statuses (204/304/HEAD).

Expand the Cloud outbound WebSocket e2e scenario to also cover standard
new WebSocket(...) connections, credentialed upgrades, and 204 responses.

This branch has not been deployed

No deployments
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.

1 participant