From f5d68d1a1891e8c4b7d362715bdcfd375411a53d Mon Sep 17 00:00:00 2001 From: Paul Murray Date: Sun, 24 May 2026 06:12:46 -0400 Subject: [PATCH 1/2] [local-proxy] fix: prevent writing response after headers are sent in LocalProxy Signed-off-by: Paul Murray --- packages/microfrontends/src/bin/local-proxy.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/microfrontends/src/bin/local-proxy.ts b/packages/microfrontends/src/bin/local-proxy.ts index 39ed036..604764e 100644 --- a/packages/microfrontends/src/bin/local-proxy.ts +++ b/packages/microfrontends/src/bin/local-proxy.ts @@ -477,6 +477,13 @@ export class LocalProxy { this.proxy = Server.createProxyServer({ secure: true }); this.proxy.on('error', (err, req, res) => { if (res instanceof http.ServerResponse) { + if (res.destroyed || res.writableEnded) return; + + if (res.headersSent) { + res.destroy(err); + return; + } + res.writeHead(500, { 'Content-Type': 'text/plain', }); @@ -701,6 +708,14 @@ export class LocalProxy { req.pipe(proxyReq); proxyReq.on('error', (err) => { logger.error('Proxy request error: ', err); + + if (res.destroyed || res.writableEnded) return; + + if (res.headersSent) { + res.destroy(err); + return; + } + res.writeHead(500, { 'Content-Type': 'text/plain' }); res.end( `Error proxying request for ${target.application} to ${hostname}:${port}${path}`, From d9e8413be2a97c8c93d003d0a78b8f4a3834c2da Mon Sep 17 00:00:00 2001 From: Paul Murray Date: Sun, 24 May 2026 06:20:15 -0400 Subject: [PATCH 2/2] add comments Signed-off-by: Paul Murray --- packages/microfrontends/src/bin/local-proxy.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/microfrontends/src/bin/local-proxy.ts b/packages/microfrontends/src/bin/local-proxy.ts index 604764e..a50516d 100644 --- a/packages/microfrontends/src/bin/local-proxy.ts +++ b/packages/microfrontends/src/bin/local-proxy.ts @@ -477,8 +477,10 @@ export class LocalProxy { this.proxy = Server.createProxyServer({ secure: true }); this.proxy.on('error', (err, req, res) => { if (res instanceof http.ServerResponse) { + /** Already closed; nothing left to send. */ if (res.destroyed || res.writableEnded) return; + /** Headers are committed; abort instead of writing a 500. */ if (res.headersSent) { res.destroy(err); return; @@ -709,8 +711,10 @@ export class LocalProxy { proxyReq.on('error', (err) => { logger.error('Proxy request error: ', err); + /** Already closed; nothing left to send. */ if (res.destroyed || res.writableEnded) return; + /** Headers are committed; abort instead of writing a 500. */ if (res.headersSent) { res.destroy(err); return;