Skip to content

forks pool mode is not compatible with use of process.send in user code #8109

@danielroe

Description

@danielroe

Describe the bug

if you have some code that might be invoked in fork, and if it checks for process.send, this will be true when vitest is running in forks mode. vitest will assume every message from process.send can be deserialised with Buffer.from, which can lead to errors.

I am currently working around by checking process.title but this may be fragile - perhaps there could be (or is?) an official way to check whether we are in a child proces we have invoked, or whether vitest has invoked it...

you may also have another suggestion

originally reported in #7082.

Reproduction

https://stackblitz.com/edit/node-fvacfgbn

// in user code
import process from 'node:process'

if (process.send) {
  // this will be received by vitest's birpc
  process.send({
    type: 'foo',
  })
}

export const thing = 42

System Info

stackblitz

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions