You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
handleWebSocket (packages/vite-plugin-cloudflare/src/websockets.ts) forwards a browser WebSocket upgrade to miniflare.dispatchFetch with createHeaders(request), which copies every request header, including Accept-Encoding: gzip.
When the Worker throws on that upgrade, workerd returns a 500 JSON error with Content-Encoding: gzip and MF-Experimental-Error-Stack. miniflare's dispatchFetch then calls response.json() without decompressing (DispatchFetchDispatcher does not inflate). That rejects with:
SyntaxError: Unexpected token '\u001f', "\u001f�\b..." is not valid JSON
On 1.43.0 the upgrade listener is async with no try/catch, so the rejection is unhandled and Node exits (exit 7). Vite HMR sockets (sec-websocket-protocol starting with vite) are skipped; Worker sockets are not.
On current main, #14862 wraps dispatchFetch in try/catch and socket.destroy()s. That stops the process death (good) but:
The Worker's exception is never revived or logged. The gzip SyntaxError is swallowed.
Two complementary fixes, neither of which is "absorb gzip in the app":
Do not forward Accept-Encoding (and other content-coding headers) on the synthetic upgrade dispatchFetch. A 101 has no body; a 500 error page should not be gzipped into response.json().
The parse itself belongs in miniflare (sibling issue). vinext currently absorbs the gzip SyntaxError so vinext dev does not exit: cloudflare/vinext#2922
Please provide any relevant error logs
SyntaxError: Unexpected token '\u001f', "\u001f�\b..." is not valid JSON
at JSON.parse (<anonymous>)
at parseJSONFromBytes (undici)
at Miniflare.dispatchFetch (miniflare)
at Server.<anonymous> (@cloudflare/vite-plugin handleWebSocket upgrade)
Node then exits with code 7 on 1.43.0 because vinext's socket-error backstop rethrows anything that is not a peer-disconnect / benign asset import.
What versions & operating system are you using?
Please provide a link to a minimal reproduction
cloudflare/vinext#2921
Describe the Bug
handleWebSocket(packages/vite-plugin-cloudflare/src/websockets.ts) forwards a browser WebSocket upgrade tominiflare.dispatchFetchwithcreateHeaders(request), which copies every request header, includingAccept-Encoding: gzip.When the Worker throws on that upgrade, workerd returns a 500 JSON error with
Content-Encoding: gzipandMF-Experimental-Error-Stack. miniflare'sdispatchFetchthen callsresponse.json()without decompressing (DispatchFetchDispatcherdoes not inflate). That rejects with:On 1.43.0 the
upgradelistener isasyncwith notry/catch, so the rejection is unhandled and Node exits (exit 7). Vite HMR sockets (sec-websocket-protocolstarting withvite) are skipped; Worker sockets are not.On current main, #14862 wraps
dispatchFetchintry/catchandsocket.destroy()s. That stops the process death (good) but:SyntaxErroris swallowed.!response.webSocketbranch, becausedispatchFetchthrows first.Two complementary fixes, neither of which is "absorb gzip in the app":
Accept-Encoding(and other content-coding headers) on the synthetic upgradedispatchFetch. A 101 has no body; a 500 error page should not be gzipped intoresponse.json().reviveErrorthe rejection, and write a non-101 response when there is one ([vite-plugin] Non-101 WebSocket upgrade responses are destroyed instead of delivered to the client in dev #15170).The parse itself belongs in miniflare (sibling issue). vinext currently absorbs the gzip
SyntaxErrorsovinext devdoes not exit: cloudflare/vinext#2922Please provide any relevant error logs
Node then exits with code 7 on 1.43.0 because vinext's socket-error backstop rethrows anything that is not a peer-disconnect / benign asset import.