Skip to content

Conversation

@AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Nov 13, 2025

Description

Resolves #9014

When user's test case doesn't do proper clean up, it can trigger rpc calls after test finished. In the reproduction there's rpc.fetch() that resolves on main thread after worker has stopped. This leads to EPIPE as IPC is closed already.

This is reproducible by having Vite plugin that takes long time on specific file transform, and that file is imported without awaiting it in test case.

Minimal repro for test/core - this will raise Error: [vitest-worker]: Closing rpc while "fetch" was pending errors on worker side so not adding the test case for now:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  plugins: [
    {
      name: 'slow-down-transform',
      enforce: 'pre',
      async resolveId(id) {
        if (id.includes('vitest-test:slow-transform')) {
          return '\0vitest-test-slow-transform'
        }
      },
      async load(id) {
        if (id.includes('vitest-test-slow-transform')) {
          await new Promise(res => setTimeout(res, 1000))
          return `export default "Hello world"`
        }
      },
    },
  ],
});
import { test } from 'vitest'

test('should not cause EPIPE when imports resolve after test finishes', async () => {
  for (const _ of Array.from({ length: 50 }).fill(0)) {
    const cache = Math.round(Math.random() * 1000)

    setTimeout(
      () =>
        import(`vitest-test:slow-transform` + `?cache=${cache}`),
      2,
    ).unref()
  }
})

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 13, 2025

@vitest/browser

npm i https://pkg.pr.new/@vitest/browser@9023

@vitest/browser-playwright

npm i https://pkg.pr.new/@vitest/browser-playwright@9023

@vitest/browser-preview

npm i https://pkg.pr.new/@vitest/browser-preview@9023

@vitest/browser-webdriverio

npm i https://pkg.pr.new/@vitest/browser-webdriverio@9023

@vitest/coverage-istanbul

npm i https://pkg.pr.new/@vitest/coverage-istanbul@9023

@vitest/coverage-v8

npm i https://pkg.pr.new/@vitest/coverage-v8@9023

@vitest/expect

npm i https://pkg.pr.new/@vitest/expect@9023

@vitest/mocker

npm i https://pkg.pr.new/@vitest/mocker@9023

@vitest/pretty-format

npm i https://pkg.pr.new/@vitest/pretty-format@9023

@vitest/runner

npm i https://pkg.pr.new/@vitest/runner@9023

@vitest/snapshot

npm i https://pkg.pr.new/@vitest/snapshot@9023

@vitest/spy

npm i https://pkg.pr.new/@vitest/spy@9023

@vitest/ui

npm i https://pkg.pr.new/@vitest/ui@9023

@vitest/utils

npm i https://pkg.pr.new/@vitest/utils@9023

vitest

npm i https://pkg.pr.new/vitest@9023

@vitest/web-worker

npm i https://pkg.pr.new/@vitest/web-worker@9023

@vitest/ws-client

npm i https://pkg.pr.new/@vitest/ws-client@9023

commit: 93d3e59

@netlify
Copy link

netlify bot commented Nov 13, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 0f9e498
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69187bc0d432890008a9f626
😎 Deploy Preview https://deploy-preview-9023--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

axel7083 added a commit to axel7083/podman-desktop that referenced this pull request Nov 14, 2025
axel7083 added a commit to axel7083/podman-desktop that referenced this pull request Nov 14, 2025
Copy link

@axel7083 axel7083 left a comment

Choose a reason for hiding this comment

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

Hey! So glad to see you working on this issue, we are in the middle of our migration to vitest 4. We have an almost 100% reproducer on GitHub, (not reproducing locally however) if you need to experiment let me know I could try to help


I also tried to downgrade to 4.0.4 but the problem still persist unit tests / ubuntu-24.04#job

@AriPerkkio AriPerkkio changed the title fix(pool): close rpc before terminating worker fix(pool): prevent writing to closed worker Nov 15, 2025
@AriPerkkio AriPerkkio mentioned this pull request Nov 15, 2025
6 tasks
@AriPerkkio AriPerkkio marked this pull request as ready for review November 17, 2025 03:44
sheremet-va
sheremet-va previously approved these changes Nov 17, 2025
@sheremet-va sheremet-va merged commit 042c60c into vitest-dev:main Nov 17, 2025
12 of 15 checks passed
@AriPerkkio AriPerkkio deleted the fix/forks-epipe branch November 17, 2025 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: write EPIPE

3 participants