- Issues
- #167
WebSocket upgrade returned by the stateless Worker gets no handshake headers
tboser opened ·
## Summary
A WebSocket upgrade returned from the stateless Worker's own `fetch` handler gets a bare `101` with none of the handshake headers, and no frames flow. The same upgrade returned from a Durable Object works. Real workerd completes the handshake in both cases.
Per RFC 6455 a client must fail a connection whose `Sec-WebSocket-Accept` is missing, so the browser drops it. The status line says `101`, which makes this read as a client bug rather than a missing response header.
## Version
`celld 0.3.0` from `ghcr.io/denoland/celld:0.3.0`. Compared against `wrangler dev` (wrangler 4.120.0) on the same `worker.js` and `wrangler.json`.
## What happened
celld, upgrade returned from the stateless Worker:
``` HTTP/1.1 101 Switching Protocols date: Mon, 24 Aug 2026 17:11:02 GMT ```
That is the whole response. No `Connection`, no `Upgrade`, no `Sec-WebSocket-Accept`, and the connection then produces nothing (`curl: (52) Empty reply from server`).
workerd, same files:
``` HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade: websocket Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= ```
celld does complete the handshake when the upgrade comes from a Durable Object. A separate worker whose top-level `fetch` forwards the request to a DO that returns the same `Response` answers:
``` HTTP/1.1 101 Switching Protocols connection: upgrade upgrade: websocket sec-websocket-accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= ```
So the machinery is there and the stateless path does not reach it.
## Expected
The stateless Worker's `101` response carries `Connection: Upgrade`, `Upgrade: websocket` and a computed `Sec-WebSocket-Accept`, and frames flow, matching the Durable Object path.
## Reproduction
`worker.js`:
```js export default { async fetch(req) { if (req.headers.get("Upgrade")?.toLowerCase() !== "websocket") { return new Response("expected an upgrade", { status: 400 }); } const pair = new WebSocketPair(); pair[1].accept(); pair[1].addEventListener("message", (e) => pair[1].send(`echo:${e.data}`)); return new Response(null, { status: 101, webSocket: pair[0] }); }, }; ```
`wrangler.json`:
```json { "name": "ws-stateless", "main": "worker.js", "compatibility_date": "2026-02-02" } ```
Then:
``` celld deploy . --bucket s3://BUCKET/ws-stateless celld --bucket s3://BUCKET/ws-stateless --listen 127.0.0.1:8095 --internal-listen 127.0.0.1:9095
curl -i -H "Connection: Upgrade" -H "Upgrade: websocket" \ -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" -H "Sec-WebSocket-Version: 13" \ http://127.0.0.1:8095/ ```
## Impact and workaround
Any app that serves a WebSocket from its top-level `fetch` handler gets a socket the browser refuses. Routing the upgrade to a Durable Object works and is what we are doing, though it forces a Durable Object on apps that otherwise need none.
## Related
#165 and #155 are both closed WebSocket handshake fixes, and #149 fixed WebSocket targets crossing service bindings. None covers an upgrade returned by the stateless Worker itself.
bartlomiejuassigned bartlomieju3 months ago on GitHub
- BA
This is now fixed and will be released this week. Thanks for the report!
bartlomiejureferenced 554fa82872e62 months ago on GitHub
bartlomiejureferenced a52f9905425b2 months ago on GitHub