Repository navigation
[vite-plugin] Retry v1 remote binding requests after preview reloads - #16899
petebacondarwin wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 3b829a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
|
| // in a `pause`d state i.e. `this.proxyData` is undefined) | ||
| // A replacement preview may already be ready when the old fetch fails. | ||
| // Drain immediately; processQueue waits if the proxy is still paused. | ||
| this.processQueue(); |
There was a problem hiding this comment.
🔴 Failed previews trigger unlimited retries
If a replacement preview rejects a GET to /read, processQueue() retries it indefinitely. newUserWorkerUrl has path /, so the active request URL /read never matches it. Requests never settle, and the proxy floods the failing preview.
Learn more
The proxy compares the full URL of the failed request with a URL built from the active preview's origin. The former contains the incoming request path; the latter defaults to /. A failure from the active preview at any other path therefore enters the stale-request retry branch. This change calls processQueue() immediately after requeuing, so another failed fetch repeats that branch without waiting for a reload.
Example: A GET to /read fails on the old preview after play announces a replacement. Its retry to the replacement also rejects. The comparison evaluates https://replacement/read against https://replacement/, and the request retries repeatedly instead of reporting the replacement's failure.
Recommended fix: Compare the failed request's preview origin with the current preview origin before classifying an error as stale. Only call processQueue() for an actual stale failure, and add a regression test where the replacement fetch also rejects.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
@petebacondarwin I think the issue here is that the original PR #16862 only changed Wrangler's proxy, while this backport changes how the remote bindings proxy behaves instead.
That being said, Devin's comment does uncover a real bug in that proxy, which main has too. I have put up #16949 to fix it on main, so we can backport that PR instead.
|
@petebacondarwin (verified author of #16862) and @edmundhung (verified human ant-core member; approved the original November 12 at 15:06:18Z, before merge): please check this v1 adaptation and approve it if it looks good. The retained private remote-bindings package bundles its own ProxyWorker through Native GitHub stack #16900 puts this PR above #16861 and below the publication-blocked Artifacts draft #16898. This fix uses the already published dependencies and can merge without waiting for that draft's release. |
commit: |
There was a problem hiding this comment.
Superseded by the review of
fc531d2b.
This review, of 11f378b1
✅ Approved — Minimal, correct fix for the retry-queue race, with tests covering both event orderings and an accurate changeset; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Risk: Low. The changeset is a patch bump for @cloudflare/vite-plugin.
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
Follows the repository conventions: the test uses the Vitest test-context expect, imports Node built-ins with the node: prefix, and the change ships with a plugin changeset.
📋 Code Quality: ✅ LGTM
Calling processQueue() right after requeueing is safe: it returns early while paused and drains immediately once resumed. The tests cover both orderings and check that the queue ends up empty.
⚡ Performance: ✅ LGTM
No performance concerns. The retry is bounded and cannot loop forever.
📝 Documentation: ✅ LGTM
The changeset accurately describes the fix.
Reviewed commit: 11f378b1
|
|
||
| Retry remote binding requests when a replacement preview is already ready | ||
|
|
||
| A retriable request could remain queued if the old preview connection failed after a remote binding session update completed. Drain the retained remote binding proxy's retry queue immediately so requests finish without waiting for another request or reload. Requests that fail on the current preview now return the error instead of hanging. |
There was a problem hiding this comment.
🔍 Internal mechanics in user-facing changelog
The changeset includes internal retry-queue mechanics, contrary to the changeset guidance. The surrounding explanation already conveys the user-facing benefit: requests finish without another request or reload.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Superseded by the review of
3b829a70.
This review, of fc531d2b
✅ Approved — The retry-queue drain and the new check on the proxyData object are correct, and the retry is bounded by preview reloads. Tests cover both event orderings and failures from the current preview; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Risk: Low. This is a focused retry fix with a patch changeset for @cloudflare/vite-plugin.
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
The change follows the repository conventions: the tests use Vitest test-context expect and import Node built-ins with the node: prefix, and the plugin change ships with a changeset.
📋 Code Quality: ✅ LGTM
this.proxyData === proxyData at ProxyWorker.ts:160 correctly recognises failures from an earlier preview. pause clears proxyData, and each play assigns a new object. A failure from the current preview is reported and rejected instead of retried. Requests other than GET and HEAD still get a 503. The tests cover both orderings and the current-preview failure case, and they follow the repository's test conventions.
⚡ Performance: ✅ LGTM
A request is retried only after a pause or play changes proxyData. A second failure with no new reload is rejected, so the number of retries is limited by the number of preview reloads.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: fc531d2b
The retained ProxyWorker treated a failed fetch as stale (from a reloaded preview) whenever the request's full URL differed from the preview's bare origin. RPC bindings connect to `/?MF-Binding=<name>`, so every failure looked like a reload. Now that a requeued request is retried immediately, a preview that keeps failing made the request retry in a loop. Comparing origins, as Wrangler does on main, doesn't work here: remote previews keep the same `<worker>.<subdomain>.workers.dev` host across reloads and only change the preview token. Compare the proxyData the request was sent with instead, since every `play` sets a new object.
f834884 to
4f39ec7
Compare
fc531d2 to
3b829a7
Compare
There was a problem hiding this comment.
✅ Approved — The retry-queue drain and the new check on the proxyData object are correct, and the retry is bounded by preview reloads. Tests cover both event orderings and failures from the current preview; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🚀 Release: ✅ LGTM
Risk: Low. This is a focused retry fix with a patch changeset for @cloudflare/vite-plugin.
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
The change follows the repository conventions: the tests use Vitest test-context expect and import Node built-ins with the node: prefix, and the plugin change ships with a changeset.
📋 Code Quality: ✅ LGTM
this.proxyData === proxyData at ProxyWorker.ts:160 correctly recognises failures from an earlier preview. pause clears proxyData, and each play assigns a new object. A failure from the current preview is reported and rejected instead of retried. Requests other than GET and HEAD still get a 503. The tests cover both orderings and the current-preview failure case, and they follow the repository's test conventions.
⚡ Performance: ✅ LGTM
A request is retried only after a pause or play changes proxyData. A second failure with no new reload is rejected, so the number of retries is limited by the number of preview reloads.
📝 Documentation: ✅ LGTM
No issues found.
Reviewed commit: 3b829a70 — same changes as fc531d2b, so this is that commit's review (no new review was run; line numbers are as of fc531d2b)
|
As discussed with Pete, I am gonna close this backport PR as the original PR does not modify the proxy worker from remote bindings. The issue flagged here will be fixed on main via #16949 and might backport to v1 following it. |
Backports #16862 to the existing retained remote-bindings ProxyWorker. During a remote binding session update, an old preview request can fail after the replacement preview's
playmessage. Its GET/HEAD retry was left queued until another request or reload. Drain the retry queue immediately, allowingprocessQueue()to wait if the proxy is still paused.The Vite plugin's retained
startRemoteProxySession→DevEnv→ProxyControllerpath bundles this template directly. Upgrading installed Wrangler cannot fix this copy. The change modifies that retained template and adds two tests against its bundled code for failure before and after resume. No absent Wrangler source or tests are restored. The resumed case fails before the fix and both cases pass afterwards. No dependency upgrades are required.Registered in native GitHub stack #16900, after #16861 and before the publication-blocked Artifacts default draft #16898. This fix can merge with the existing published dependencies; #16898 remains draft pending npm publication.
Validation:
pnpm build,pnpm check, andpnpm test:ci; the retained proxy regression covers both event orderings. The test initially needed adjustment for the package's ES library andnoImplicitOverride; final checks are recorded after those adjustments. Formatting andgit diff --checkpass. Credentialed remote E2E tests are not run.Note
This is a contribution from an AI agent: Codex.