vitest: Segmentation fault when a breakpoint is attached in VS Code

Describe the bug

When running in VS Code with the recommended launch script from https://vitest.dev/guide/debugging.html, Vitest will error out with a 139 / Segmentation Fault if and only if a breakpoint is attached anywhere in the test file.

josh@LAPTOP-B0MQCQ9I:~/repos/repros$  cd /home/josh/repos/repros ; /usr/bin/env 'NODE_OPTIONS=--require /home/josh/.vscode-server/bin/899d46d82c4c95423fb7e10e68eba52050e30ba3/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.29903-9.sock","deferredMode":false,"waitForDebugger":"","execPath":"/usr/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","mandatePortTracking":true,"fileCallback":"/tmp/node-debug-callback-6863962514e5d6e5"}' /usr/bin/node ./node_modules/vitest/vitest.mjs run src/index.test.js
Debugger attached.

 RUN  /home/josh/repos/repros

Segmentation fault

This seems unrelated to the other 2-3 segfault issues.

Reproduction

https://github.com/JoshuaKGoldberg/repros/tree/vitest-segmentation-fault

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 12.01 GB / 24.94 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.13.0 - /usr/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/bin/npm
  npmPackages:
    vitest: ^0.4.1 => 0.4.1

Used Package Manager

yarn

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 21 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve managed to get to here before it segfaults: https://github.com/vitest-dev/vitest/blob/main/packages/vitest/src/node/execute.ts#L19

Here is the call stack, right up to the point before it segfaults:

cachedRequest (/Users/me/workspace/next-page-tester/node_modules/vitest/dist/chunk-vite-node-utils.d38851ea.js:9318)
executeFile (/Users/me/workspace/next-page-tester/node_modules/vitest/dist/chunk-vite-node-utils.d38851ea.js:9311)
executeInViteNode (/Users/me/workspace/next-page-tester/node_modules/vitest/dist/worker.js:245)
await (Unknown Source:1)
startViteNode (/Users/me/workspace/next-page-tester/node_modules/vitest/dist/worker.js:283)
run (/Users/me/workspace/next-page-tester/node_modules/vitest/dist/worker.js:331)
<anonymous> (/Users/me/workspace/next-page-tester/node_modules/tinypool/dist/esm/worker.js:96)
await (Unknown Source:1)
onMessage (/Users/me/workspace/next-page-tester/node_modules/tinypool/dist/esm/worker.js:123)
atomicsWaitLoop (/Users/me/workspace/next-page-tester/node_modules/tinypool/dist/esm/worker.js:81)
<anonymous> (/Users/me/workspace/next-page-tester/node_modules/tinypool/dist/esm/worker.js:68)
await (Unknown Source:1)
<anonymous> (/Users/me/workspace/next-page-tester/node_modules/tinypool/dist/esm/worker.js:69)
[nodejs.internal.kHybridDispatch] (internal/event_target:643)
exports.emitMessage (Unknown Source:23)
callbackTrampoline (internal/async_hooks:130)
MESSAGEPORT (Unknown Source:1)
init (internal/inspector_async_hook:25)
emitInitNative (internal/async_hooks:201)

From cachedRequest directRequest gets called and vm.runInThisContext runs triggering the segfault.

It’s this:

https://user-images.githubusercontent.com/936006/155585500-f5eac2dd-3ca5-4057-b676-313c5f745243.mp4

which I’m guessing is related to https://github.com/nodejs/node/issues/37648 why it only happens on debugger I don’t know.

Location in code

https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/client.ts#L121-L124

System Details

  System:
    OS: macOS 11.6.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 172.20 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.6.0 - ~/.nvm/versions/node/v17.6.0/bin/node
    npm: 8.5.1 - ~/.nvm/versions/node/v17.6.0/bin/npm
  Browsers:
    Chrome: 98.0.4758.102
    Safari: 14.1.2
  npmPackages:
    vitest: 0.5.5 => 0.5.5 

Segfault output

PID 36748 received SIGSEGV for address: 0x3730858f410b
0   segfault-handler.node               0x00000001104390aa _ZL16segfault_handleriP9__siginfoPv + 298
1   libsystem_platform.dylib            0x00007fff20558d7d _sigtramp + 29

CC @connor4312

Thanks for the ping. Unfortunately not a whole lot we can do on the VS Code side for cases like this.

I noticed that my “Node.js” version in vscode was the same as that of @TrickyPi, but the version I am running in command line was v16.14.0.

I decided to downgrade my version of node (with nvm) to v14.16.0 (to match vscode’s version) and the error stopped appearing. I started trying different versions of node, from 14.16 and up, and once I hit v16.8.0, the segmentation fault starts to occur.

Here is the complete list of versions I tried: Versions that work: v14.19.0, v15.12.0, v16.0.0, v16.3.0, v16.5.0, v16.7.0 Versions that resulted in segfault: v16.8.0, v16.13.0, v16.14.0, v17.5.0