Repository navigation
Wait for the new Runtime version after a hosted deployment - #376
Conversation
A new Worker version takes a few seconds to reach every Cloudflare location. The hosted deployment checked the Runtime version once, right after `wrangler deploy`, and failed when that request still reached the previous version, leaving the control plane undeployed. It now checks again every two seconds for up to a minute.
| { attempts = 30, interval = 2_000 } = {}, | ||
| ) => { | ||
| for (let attempt = 1; ; attempt++) { | ||
| if ((await read()) === version) return; |
There was a problem hiding this comment.
A brief error stops deployment
If Cloudflare returns a temporary HTTP 503 after wrangler deploy, the version check throws and skips the remaining attempts. The control plane never deploys, even if the next check would reach the new Runtime. Retry temporary read errors and test that the wait succeeds when the next check returns the expected version.
| { attempts = 30, interval = 2_000 } = {}, | ||
| ) => { | ||
| for (let attempt = 1; ; attempt++) { | ||
| if ((await read()) === version) return; | ||
|
|
||
| if (attempt >= attempts) throw new Error("The requested Runtime version is not active"); | ||
| await new Promise((resolve) => setTimeout(resolve, interval)); |
There was a problem hiding this comment.
waitForRuntimeVersion counts checks, not time. The pauses alone can take 58 seconds. If 30 checks each take a second and return the old version, the wait takes about 88 seconds, with database locks blocking app provisioning and Runtime updates the whole time. Use one deadline that also limits how long the code waits for a check to finish.
A new Worker version takes a few seconds to reach every Cloudflare location.
deploy-hostedread the Runtime version once, right afterwrangler deployreturned, and failed with "The requested Runtime version is not active" when that request still reached the previous version. The Runtime was then already on the new version, but the control plane had not been deployed, and a rerun was needed.The check now repeats every two seconds for up to a minute and fails only if the new version still does not answer.
Testing
pnpm checktests/cloudflare/hosted-installation.test.ts: the wait resolves once the new version answers and fails after its attempts when it never does.Fix the wait before merging so transient read errors can recover and slow reads cannot hold deployment locks past the promised minute.
Findings
Summary
deploy-hostednow polls for the requested Runtime version before continuing to the control-plane deploy.Reviews (1) · Last reviewed commit: "Wait for the new Runtime version after a..." · Reviewed by Greptile