Repository navigation
Miniflare waits forever when workerd starts but never reports ready #17025
workers-devprod
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Moved from #16939. Originally opened by webbertakken on 2026-11-15.
Note: This issue was written by my clanker. While I try to verify its steps as much as possible, it might not be 100% correct.
What versions & operating system are you using?
Describe the Bug
When
workerdstarts but never writes itslistenevents to the control pipe,Runtime.updateConfig()waits in
waitForPorts()with no limit. #14077 fixed the case whereworkerdexits early (the controlstream ends); a
workerdthat stays alive is still awaited for ever.We meet it on a host under memory pressure. The OOM killer SIGTERMs
workerdduring a@cloudflare/vitest-pluginrun. Miniflare logsThe Workers runtime crashed unexpectedly and is being restarted(crash #1 to #4), thenERR_RUNTIME_FAILURE: The Workers runtime failed to restart after an unexpected crash. The next pool worker'snew Miniflare()then starts aworkerdthat stays alive atabout 6.6 MB RSS and 0 % CPU and never reports its ports.
waitForMiniflareReady()awaitsmf.ready,so the Vitest run prints nothing more and never exits; ours waited 22 minutes until an outer timeout.
Vitest also reports a pool worker that failed to start only in its final summary, so even a bounded
start costs each remaining test file its own wait before anything is printed.
Reproduction
MINIFLARE_WORKERD_PATHthat runs the real binary until a flag file exists, thenruns
exec sleep 3600(alive, never ready).@cloudflare/vitest-pluginrun of a few test files; after the first file starts, create theflag and
pkill -TERMthe runningworkerd.Expected
The runtime start fails within a bound, with an
ERR_RUNTIME_FAILUREthat says so, and thetest pool reports it when it happens.
Proposal
waitForPorts()inRuntime.updateConfig()(an option such asruntimeStartupTimeout, default 60 s); on expiry SIGKILL the process and throwMiniflareCoreError("ERR_RUNTIME_FAILURE", "The Workers runtime did not report ready within N ms").This covers both a first start and the crash-restart path (
#handleWorkerdCrash), which then sets#runtimeRestartErroras it does today.so a runner can stop at the first one. We carry both as a local patch:
waitForMiniflareReady()racesmf.readywith a 60 s timer, printsERR_RUNTIME_FAILUREat once and disposes the instance withoutawaiting it (its dispose awaits the same start). Normal starts on that host take 0.3 to 1.4 s.
Happy to open a PR for either part.
workers-devprod commented on 2026-11-15:
Automated triage
Issue assessment
bug(high)package:miniflare(high)package:vitest(medium)Actionability and missing information
Miniflare hangs forever in waitForPorts() when workerd starts but never reports ready (e.g. after crash-restarts under the vitest plugin on an OOM-killed host); report gives versions, environment, repro steps, expected bounded failure, and a proposed runtimeStartupTimeout fix.
Reproduction reason: Report provides explicit versions and concrete steps using a MINIFLARE_WORKERD_PATH wrapper that leaves workerd alive without reporting ports.
Reproduction
Evidence and attempted steps
Steps attempted:
git clone --depth 1 https://github.com/cloudflare/workers-sdk.gitpnpm installnode_modules/.pnpm/@cloudflare+workerd-linux-64@1.20261110.1/node_modules/@cloudflare/workerd-linux-64/bin/workerd --versionbash run-baseline.shbash run-reproduction.shExpected behavior: Per the issue: the runtime start should fail within a bound with an ERR_RUNTIME_FAILURE that says so (e.g. "The Workers runtime did not report ready within N ms"), so the start (first start or crash-restart) fails visibly instead of hanging, and the vitest pool would report the failure when it happens.
Observed behavior: Miniflare 5.20261110.2-beta never settles mf.ready: the repro logged "still waiting for mf.ready..." every 5s from 5.0s to 55.0s with no failure output and no ERR_RUNTIME_FAILURE, and an outer
timeout 60had to SIGTERM the run (exit code 124, "startup never completed" after 59.5s). During the wait the runtime substitute was alive and idle (ps: state S, 0.0% CPU), so the process-exit race added by #14077 could not fire. Baselines in the same sandbox: real bundled workerd (workerd 1.20261110.1) reached mf.ready in 0.2s, and a runtime that exits before reporting ready rejected mf.ready in under 0.1s with MiniflareCoreError [ERR_RUNTIME_FAILURE] — confirming the machinery works and the hang is specific to an alive-but-silent runtime, as reported.Artifact: Download reproduction archive (Cloudflare Access required).
This summary was generated by an LLM and may contain errors. Please verify its findings.
Triage bot commands and options
Repository collaborators with write or admin access can trigger actions by commenting on this issue:
@workers-devprod reproduce: Attempt to reproduce the issue using its description and recent comments.DYNOSuprovo commented on 2026-11-16:
Hi @cloudflare/workers-devprod,
I reviewed the reproduction logs and the control pipe stream lifecycle in Miniflare's Runtime.updateConfig().
The issue is that waitForPorts() only races #portsPromise against #runtimeExitPromise:
s const ports = await Promise.race([ this.#portsPromise, this.#runtimeExitPromise, ]);If workerd remains alive (e.g. stalled or silent under host memory constraints) without emitting listen events on the control stream, #runtimeExitPromise never fires, leaving #portsPromise hanging indefinitely until the outer test suite runner times out.
Proposed Solution
untimeStartupTimeout?: number option (defaulting to 60,000 ms) in RuntimeOptions.
` s
const timeout = this.#options.runtimeStartupTimeout ?? 60_000;
let timer: NodeJS.Timeout | undefined;
const startupTimeoutPromise = new Promise((_, reject) => {
timer = setTimeout(() => {
this.#process?.kill("SIGKILL");
reject(new MiniflareCoreError("ERR_RUNTIME_FAILURE", The Workers runtime did not report ready within \ ms));
}, timeout);
});
try {
const ports = await Promise.race([
this.#portsPromise,
this.#runtimeExitPromise,
startupTimeoutPromise,
]);
clearTimeout(timer);
return ports;
} catch (err) {
clearTimeout(timer);
throw err;
}
`
3. In @cloudflare/vitest-plugin, handle this error cleanly in waitForMiniflareReady() so runner pools report the initialization failure immediately.
I have this implementation and regression tests prepared. Could a maintainer please vouch for me so I can open the PR against cloudflare/workers-sdk?
All reactions