Skip to content

[microfrontends] Guard local proxy error responses after headers sent#56

Open
plmrry wants to merge 2 commits into
mainfrom
paul/prevent-writing-when-headers-sent
Open

[microfrontends] Guard local proxy error responses after headers sent#56
plmrry wants to merge 2 commits into
mainfrom
paul/prevent-writing-when-headers-sent

Conversation

@plmrry
Copy link
Copy Markdown
Member

@plmrry plmrry commented May 24, 2026

Description

The proxy will occasionally write to the response after headers have already been written, causing:

Error [ERR_HTTP_HEADERS_SENT]: Cannot write headers after they are sent to the client

AI-Description (by Codex)

This PR guards the local proxy error handlers before writing a fallback 500 response.

The HTTPS production fallback path can receive an upstream request error after it has already forwarded response headers to the browser. In that state, calling res.writeHead(500, ...) throws ERR_HTTP_HEADERS_SENT and crashes the proxy. The handler now returns when the response is already closed, and destroys the response when headers have already been committed.

The same guard is also applied to the http-proxy error path, which had the same unguarded writeHead(500) behavior.

Validation: not run. This branch intentionally keeps the change minimal and only updates the response-state guards.

plmrry added 2 commits May 24, 2026 06:12
… LocalProxy

Signed-off-by: Paul Murray <paul.murray@vercel.com>
Signed-off-by: Paul Murray <paul.murray@vercel.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nextjs-app-docs Ready Ready Preview, Comment May 24, 2026 10:52am
nextjs-app-marketing Ready Ready Preview, Comment May 24, 2026 10:52am
nextjs-pages-blog Ready Ready Preview, Comment May 24, 2026 10:52am
nextjs-pages-dashboard Ready Ready Preview, Comment May 24, 2026 10:52am
react-router-docs Ready Ready Preview, Comment May 24, 2026 10:52am
react-router-vite-base-path Ready Ready Preview, Comment May 24, 2026 10:52am
react-router-web Ready Ready Preview, Comment May 24, 2026 10:52am
single-spa-root Ready Ready Preview, Comment May 24, 2026 10:52am
single-spa-shared Ready Ready Preview, Comment May 24, 2026 10:52am
single-spa-web Ready Ready Preview, Comment May 24, 2026 10:52am
sveltekit-docs Ready Ready Preview, Comment May 24, 2026 10:52am
sveltekit-web Ready Ready Preview, Comment May 24, 2026 10:52am

Request Review

@plmrry plmrry self-assigned this May 24, 2026
@plmrry plmrry marked this pull request as ready for review May 24, 2026 10:57
@plmrry plmrry enabled auto-merge (squash) May 24, 2026 10:58
@plmrry plmrry requested a review from anthonyshew May 25, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant