Skip to content

fix(cloudflare): handle aborted response body in miniflare worker proxy - #1457

Merged
john-royal merged 2 commits into
mainfrom
john/mf-abort-body
Jul 24, 2026
Merged

fix(cloudflare): handle aborted response body in miniflare worker proxy#1457
john-royal merged 2 commits into
mainfrom
john/mf-abort-body

Conversation

@john-royal

@john-royal john-royal commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Attach an 'error' listener on the Miniflare response body stream so a client disconnect mid-response destroys the Node response instead of crashing the process with an unhandled 'error' event.
  • Fixes flaky alchemy dev deaths during aborted fetches (e.g. Playwright navigation/teardown).
  • Closes alchemy-run/alchemy#938 (filed against alchemy; fix lands in alchemy-async).

Test plan

  • Run alchemy dev with a worker that returns a slow/streaming response
  • Abort requests mid-flight (browser nav, Playwright, or the repro from the issue) and confirm the process stays up
  • Confirm normal non-aborted responses still complete correctly
// Before: abort mid-response → unhandled AbortError kills alchemy dev
// After: abort mid-response → body error is handled, process keeps running
if (res.body) {
  const body = Readable.fromWeb(res.body);
  body.on("error", () => out.destroy());
  body.pipe(out, { end: true });
}

Made with Cursor

Client disconnects mid-response were emitting an unhandled stream 'error' that killed the alchemy dev process. Swallow the abort on the body Readable so the proxy tears down the response instead.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pkg-pr-new

pkg-pr-new Bot commented Jul 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/alchemy@1457

commit: 82b4d32

…proxy

Use a slow streaming worker and destroy connections on first body byte so the race reproduces reliably under Node, including on fast machines where early AbortController aborts often miss the pipe window.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL: https://c6c43011-alchemy-website.alchemy-run.workers.dev

This preview was built from commit d778276


🤖 This comment will be updated automatically when you push new commits to this PR.

@john-royal
john-royal merged commit aeabfdf into main Jul 24, 2026
6 checks passed
@john-royal
john-royal deleted the john/mf-abort-body branch July 24, 2026 15:27
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.

dev: client disconnect mid-response kills the alchemy dev process (unhandled 'error' in miniflare worker proxy)

1 participant