fix: skip peer worker forwarding when action was already forwarded#93710
Open
elishagreenwald wants to merge 2 commits intovercel:canaryfrom
Open
fix: skip peer worker forwarding when action was already forwarded#93710elishagreenwald wants to merge 2 commits intovercel:canaryfrom
elishagreenwald wants to merge 2 commits intovercel:canaryfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-forwardedis 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?
selectWorkerForForwardingfor peer forwarding when forwarding is allowed (not when the action was already forwarded, and not without anactionId). Exposed asselectPeerWorkerForForwardingfor a single, testable gate.action-handler.test.ts, plus an app-dir e2e case with middleware rewriting the pathname (node + edge runtimes).Fixes #84504
Supersedes #84525, #92053
Fixes #