Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when a breakpoint is attached in VS Code #795

Closed
6 tasks done
JoshuaKGoldberg opened this issue Feb 18, 2022 · 21 comments
Closed
6 tasks done

Segmentation fault when a breakpoint is attached in VS Code #795

JoshuaKGoldberg opened this issue Feb 18, 2022 · 21 comments
Labels
help wanted Extra attention is needed

Comments

@JoshuaKGoldberg
Copy link
Contributor

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

@sheremet-va sheremet-va added bug help wanted Extra attention is needed labels Feb 19, 2022
@raulcesar
Copy link

I have also been having this problem, and have noticed it exists also in the Peeky testrunner project
Hope this information helps.

@Demivan
Copy link
Member

Demivan commented Feb 19, 2022

Another hint is that it happens even with threads disabled

@TrickyPi
Copy link
Contributor

image

I didn't encounter this problem, it works...

@Demivan
Copy link
Member

Demivan commented Feb 22, 2022

@TrickyPi What Vitest and Node version are you using. And what package manager?

@TrickyPi
Copy link
Contributor

TrickyPi commented Feb 22, 2022

Vitest: v0.4.1
Node version: v16.13.1
package manager: yarn (version:v1.22.15)

@TrickyPi
Copy link
Contributor

My vscode info:
Version: 1.63.2 (Universal)
Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
Date: 2021-12-15T09:37:28.172Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin arm64 20.6.0

@raulcesar
Copy link

@TrickyPi, could you share your debugger launch config?

@TrickyPi
Copy link
Contributor

image

same as here https://vitest.dev/guide/debugging.html#vscode

@raulcesar
Copy link

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

@TrickyPi
Copy link
Contributor

TrickyPi commented Feb 22, 2022

I changed my node version to v16.14.0,
image
it also works.

@raulcesar
Copy link

Strange... when I run with v16.14.0, I get the error.
Made a very simple project (https://github.com/raulcesar/vscode-debug-segfault).
Here is the test:
test-code

And here is the result:
error-screenshot

@TrickyPi, with node v16.14.0, are you running vs code from command line (to make sure that VS-Code is running on that version)?

@TrickyPi
Copy link
Contributor

TrickyPi commented Feb 22, 2022

~~Oh~, i did't use command line.
image
when i use command line to start debugging, the segmentation fault starts to occur.~~
it also works.
image

@raulcesar
Copy link

Strange.

I fired up a virtual machine to start from a clean environment. Installed windows (thought maybe something to do with linux environment).

Installed node 16.4.0
Installed vs studio code (info below).

Version: 1.64.2 (user setup)
Commit: f80445acd5a3dadef24aa209168452a3d97cc326
Date: 2022-02-09T22:02:28.252Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19042

Used simple project with just vite and vitest installed as dependencies, and still got segmentation fault
Also asked a colleague from work to do the same test, and he also got the error.

node-version

vs-code-error-on-windows

@raulcesar
Copy link

On this screen, the error has a little more information:
vs-code-error-on-windows-2

@jasonwilliams
Copy link

jasonwilliams commented Feb 24, 2022

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:

secondSeg.mp4

which I'm guessing is related to nodejs/node#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

@connor4312
Copy link

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

@jasonwilliams
Copy link

@connor4312 do you have any inclination as to why it would only happen when in debug mode? But not when running node directly?

@connor4312
Copy link

Not really, though I am not an expert on V8 internals. But in general crashes when only in debug mode are not unprecedented. The debugger and the information it asks for will touch many more features of the runtime than any given program is likely to.

@raulcesar
Copy link

raulcesar commented Mar 1, 2022

Hey guys, just did a recent update on my computer and decided to run some tests to see if anything changed.
the TLDR of it is that I think the problem has been corrected with vite 2.8.5 and vitest 0.5.8.

Read on for the slightly longer story:

I found that when I used YARN or NPM (as opossed to PNPM) to install dependencies, the debugger worked without any problems.
So I tried updating caches, comparing the "lock" files, etc. In the end, I ended up running a pnpm -up vite --latest -r, which upgraded vite to (2.8.5 and vitest to 0.5.8. After this, the segfault went away when using PNPM as well.

So here is the list of the tools I used (with versions):

VSCode:
Version: 1.64.2
Commit: f80445acd5a3dadef24aa209168452a3d97cc326
Date: 2022-02-10T19:07:05.314Z
Electron: 13.6.9
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.40-electron.0
OS: Linux x64 5.16.11-arch1-1

node: version: 16.14.0
yarn: version 1.22.17
npm: version 8.3.1
pnpm: 6.32.1

With this configuration, here are the result:

vite v. 2.8.4 and vitest v. 0.5.1

If I use vite version 2.8.4 (with vitest 0.5.1):
YARN: works OK
NPM: works OK
PNPM: SEGFAULT (ONLY ON DEBUGGER). Works perfectly with "pnpm run test".

vite version 2.8.5 and vitest 0.5.8::

YARN: works OK
NPM: works OK
PNPM: works OK

In my test project (https://github.com/raulcesar/vscode-debug-segfault), I have 2 commits with tags "SEGFAULT" and "NO-SEGFAULT" that illustrate the changes to dependencies.

Anyway, I hope this helps, and just want to say that I am loving vite and vitest, and will be using them both in an upcoming project.

@jasonwilliams
Copy link

I can also confirm that debugging works without segmentation faults on v0.5.9

@DannyFeliz
Copy link
Contributor

should we close this issue then?

chaii3 pushed a commit to chaii3/vitest that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

8 participants