Skip to content

fix: skip peer worker forwarding when action was already forwarded#93710

Open
elishagreenwald wants to merge 2 commits intovercel:canaryfrom
elishagreenwald:fix/action-peer-forward-84504
Open

fix: skip peer worker forwarding when action was already forwarded#93710
elishagreenwald wants to merge 2 commits intovercel:canaryfrom
elishagreenwald:fix/action-peer-forward-84504

Conversation

@elishagreenwald
Copy link
Copy Markdown

What?

Stops the server action handler from choosing a peer worker to forward to when the request was already forwarded (so we do not chain peer forwards when x-action-forwarded is set).

Why?

Under some middleware rewrites / same-host forwards, the handler could run peer-forward selection again and wedge the server (infinite or runaway peer-forward / memory pressure), as in #84504.

How?

  • Runtime: only call selectWorkerForForwarding for peer forwarding when forwarding is allowed (not when the action was already forwarded, and not without an actionId). Exposed as selectPeerWorkerForForwarding for a single, testable gate.
  • Tests: Jest coverage in action-handler.test.ts, plus an app-dir e2e case with middleware rewriting the pathname (node + edge runtimes).

Fixes #84504
Supersedes #84525, #92053

  • Bug fix — issue linked with Fixes #
  • Tests added (unit + e2e)
  • Signed / verified commits on the branch

elishagreenwald and others added 2 commits May 8, 2026 15:18
Avoid infinite peer-forward loops when middleware rewrites paths or the
request was already forwarded (x-action-forwarded). The receiving worker
short-circuits the forwarding decision and falls through to lenient
serverModuleMap resolution instead of forwarding again.

Adds a self-contained e2e regression test that reproduces the loop via a
proxy.ts rewrite: with the fix the request resolves in ~150ms; without
the fix it hangs until the test's 10s abort timer fires.

Fixes vercel#84504
Supersedes vercel#84525, vercel#92053
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forwarded server actions with middleware rewrites cause an infinite request loop

1 participant