Skip to content

fix: keep per-file isolation in vm pools when maxWorkers is 1 - #10743

Merged
sheremet-va merged 1 commit into
mainfrom
fix/vm-pool-single-worker-isolation
Jul 10, 2026
Merged

sheremet-va merged 1 commit into
mainfrom
fix/vm-pool-single-worker-isolation

Conversation

@sheremet-va

Copy link
Copy Markdown
Member

Description

vm pools resolve isolate to false during config resolution — their isolation comes from a fresh VM context per run request, not from worker lifecycle. The single-worker batching in groupSpecs treated that resolved flag as a user opt-in: with maxWorkers: 1, all same-environment files were packed into one run request, and runVmTests executes a whole run request in a single VM context. Every test file then shared one context — globalThis, DOM and module state leaked across files:

// a.test.ts
test('pollutes', () => {
  globalThis.__leaked = 'from a'
})

// b.test.ts — fails with vmThreads + maxWorkers: 1, passes with maxWorkers >= 2
test('isolated', () => {
  expect(globalThis.__leaked).toBeUndefined()
})

vmThreads/vmForks are now excluded from that batching and fall back to one run request per file on the shared worker, restoring the same per-file context isolation as any other maxWorkers value. No opt-in is lost: explicit isolate settings are already overwritten for vm pools, so isolate: false there never expressed user intent to share state.

@netlify

netlify Bot commented Jul 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 634cece
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6a4e7da625d0fd0008c100f7
😎 Deploy Preview https://deploy-preview-10743--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
sheremet-va requested a review from AriPerkkio July 8, 2026 16:42

@AriPerkkio AriPerkkio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper fix for this should be that vm pools themselves handle vm context recycling. They should be able to receive all specs from main thread in a single batch.

This PR seems to add work-around.

@sheremet-va
sheremet-va merged commit 83ab9a4 into main Jul 10, 2026
28 of 29 checks passed
@sheremet-va
sheremet-va deleted the fix/vm-pool-single-worker-isolation branch July 10, 2026 13:09
@hi-ogawa

Copy link
Copy Markdown
Collaborator

Oh well, I was just about to report the bug and realized it's fixed already 😄

@AriPerkkio

Copy link
Copy Markdown
Member

Proper fix for this should be that vm pools themselves handle vm context recycling. They should be able to receive all specs from main thread in a single batch.

Actually this might not be possible due to how vmMemoryLimit works. So the approach this PR introduced is probably the only way to do it simply.

I wonder if vmMemoryLimit was actually broken due to this bug. 🙃

@github-actions github-actions Bot locked and limited conversation to collaborators Jul 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants