From 5c6b19852fd0c7e231ba0a1993438a898d2ebc43 Mon Sep 17 00:00:00 2001 From: Nic Miller Date: Mon, 3 Aug 2026 09:25:06 +0100 Subject: [PATCH] fix: don't crash the CLI when the upstream dev server dies mid-response --- src/utils/proxy.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts index ac65ffabae6..2806a2b46ac 100644 --- a/src/utils/proxy.ts +++ b/src/utils/proxy.ts @@ -556,6 +556,15 @@ const initializeProxy = async function ({ } if (res instanceof http.ServerResponse) { + if (res.headersSent || res.writableEnded) { + // The upstream died mid-response: headers are already on the wire, so + // `writeHead` below would throw ERR_HTTP_HEADERS_SENT out of this event + // handler and terminate the whole CLI (see #5917). The response is + // unsalvageable — drop the socket and keep the dev server alive so + // requests after the upstream comes back succeed. + res.destroy() + return + } res.writeHead(500, { 'Content-Type': 'text/plain', })