[miniflare] A Worker answering a WebSocket upgrade with 204 or 304 crashes the process
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 86/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Start in packages/miniflare/src/http/fetch.ts at the unexpected-response handler, which the issue identifies as passing the response stream to the Response constructor. Check how it handles 204, 205, and 304, then run the relevant Miniflare fetch tests. Done means dispatchFetch resolves with the Worker's 204 or 304 response instead of crashing the process.
Written by the indexing model from the issue text.
Description
What versions & operating system are you using?
miniflare 5.20261123.1-beta (built from main at 41bacf7ce), undici 7.30.2, ws 8.21.0, Node.js 26.13.1, Linux x64
Please provide a link to a minimal reproduction
No repository; this script reproduces it:
import { Miniflare } from 'miniflare';
const mf = new Miniflare({
workers: [{
config: {
name: '', compatibilityDate: '2026-11-01',
manifest: { mainModule: 'index.mjs', modules: { 'index.mjs': { type: 'esm', contents: 'export default { fetch() { return new Response(null, { status: 204 }); } }' } } },
env: {}, exports: {},
},
}],
});
try {
const res = await mf.dispatchFetch('http://localhost/', { headers: { Upgrade: 'websocket' } });
console.log('resolved', res.status);
} catch (error) {
console.log('caught', error.message);
}
Describe the Bug
When a Worker answers a WebSocket upgrade with a 204 or 304, dispatchFetch crashes the Node.js process instead of returning the response, and the catch above never runs.
The unexpected-response handler in packages/miniflare/src/http/fetch.ts passes the response stream as the body, new Response(req, { status: req.statusCode, headers }), and undici rejects a body for 204, 205, and 304.
It throws inside the ws event, so callers of dispatchFetch, such as @cloudflare/vite-plugin in vite dev, can't catch it.
Expected: dispatchFetch resolves to the Worker's 204.
Passing null as the body for those statuses would fix it.
Please provide any relevant error logs
TypeError: Response constructor: Invalid response status code 204
at initializeResponse (undici/lib/web/fetch/response.js:528:27)
at new Response (undici/lib/web/fetch/response.js:145:5)
at new _Response (miniflare/dist/src/index.js:35880:9)
at WebSocket.<anonymous> (miniflare/dist/src/index.js:36655:25)
at ClientRequest.<anonymous> (ws/lib/websocket.js:929:27)
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 1.7k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 282
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/workers-sdk
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
cloudflare/workers-sdk#17189 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudflare/workers-sdk#17187 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
cloudflare/workers-sdk#17175 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/workers-sdk#17174 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
cloudflare/workers-sdk#17165 · 1 comment ·
Maintainers usually reply within 1 day
All issues in cloudflare/workers-sdk
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
bug severity:low triage:confirmed triage:in-progress
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Cotal-AI/Cotal#10749 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-atl
Difficulty 1/5 Under an hour Newbie friendliness 88/100
GoogleChrome/modern-web-guidance-src#3726 ·
Maintainers usually reply within 1 day
-
e2e-failure ready-to-code
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4935 · 1 comment ·
Maintainers usually reply within 1 day