[miniflare] Support workerd V8 flags via MINIFLARE_WORKERD_V8_FLAGS environment variable#14702
[miniflare] Support workerd V8 flags via MINIFLARE_WORKERD_V8_FLAGS environment variable#14702Sipixer wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 4136d01 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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:
Show detailed file reviewers
|
|
I think that the fact that the memory keeps growing in a Vite setup on each build indicates we have a real memory leak in the system somewhere. So far we have not been able to identify the cause, but we would rather try to fix it than patch over it with an increased heap size. We're going to have a dig around to see if we can fix the leak, but if not then we can return to this fix later next week. |
|
I dug into the leak you mentioned and prototyped a fix (13 lines in the bundled runner-worker, −58% live memory, stack traces unaffected) — details and measurements in #14701 (comment). |
Relates to #14701 (immediate mitigation — the underlying heap retention and crash recovery are tracked there and in #13045).
Support passing V8 flags to
workerdvia aMINIFLARE_WORKERD_V8_FLAGSenvironment variable, mirroring the existingMINIFLARE_WORKERD_AUTOGATESpassthrough (#8431). The generatedworkerdconfig already supportsv8Flags; Miniflare just never populated it, so the runtime always runs with V8's default ~1.4 GB heap limit and there is no way to raise it.Large dev applications served through
@cloudflare/vite-plugincan reach that limit during a normal editing session (each server-file edit re-evaluates the invalidated module graph inside the isolate — measurements in #14701). When it happens,workerdaborts withV8 fatal error; location = Reached heap limitand every subsequentdispatchFetch()returnsfetch faileduntil the dev server is manually restarted. Setting e.g.MINIFLARE_WORKERD_V8_FLAGS="--max-old-space-size=4096"keeps those sessions alive.MINIFLARE_WORKERD_V8_FLAGS="--max-old-space-size=256"workerd OOMs at exactly 255.9 MB on first render (vs the ~1.4 GB default); with--max-old-space-size=4096, 70 consecutive edit/request cycles that previously crashed the runtime complete with zero failures. Also verified the variable being unset produces a config identical to before (emptyv8Flagslist).MINIFLARE_WORKERD_AUTOGATESescape hatch; both are internal/debugging environment variables.