Segfault With Recent Versions Of Node And Native VS Code Debugging

by ADMIN 67 views

===========================================================

Introduction

In recent versions of Node, specifically v23.11.0, v24.0.0, and v24.0.1, users have reported experiencing a segmentation fault (core dumped) error when using native VS Code debugging. This issue is particularly puzzling as it only occurs when using the native debugger, and the same command executed on the command line runs without issues.

Reproduction Steps

Unfortunately, the user is unable to provide a minimal reproduction repository. However, they have provided detailed information about their setup and the steps they have taken to reproduce the issue.

Platform and Subsystem

The user is running on a Linux P3 6.8.0-59-generic #61~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:03:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux platform. The subsystem is not responding.

Command Executed by VS Code

The command executed by VS Code is as follows:

/usr/bin/env TS_NODE_PROJECT=/path/to/tsconfig.json 'ENV_ONE=VALUE_ONE' 'ENV_TWO=VALUE_TWO' ENV_THREE=VALUE_THREE ENV_FOUR=VALUE_FOUR 'NODE_OPTIONS= --require /usr/share/codium/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js  --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"/tmp/node-cdp.83350-f9cd27da-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"/usr/local/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-f9d390cd3c6fd40d"}' /usr/local/bin/node --require ts-node/register ./src/application/main.ts

This command is executed using the n npm package to change node versions.

Expected Behavior

The expected behavior is that the application starts as normal, stopping on breakpoints within the code editor as with previous versions.

Actual Behavior

However, the actual behavior is that the application crashes with a segmentation fault (core dumped) error.

Stacktrace

The stacktrace is as follows:

PID 83717 received SIGSEGV for address: 0x0
.../node_modules/segfault-handler/build/Release/segfault-handler.node(+0x33b0)[0x7d1e7607a3b0]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7d1e75a42520]
/usr/local/bin/node(_ZN2v87Context5EnterEv+0x11)[0x1334fb1]
/usr/local/bin/node(_ZN12v8_inspector14InjectedScript5Scope10initializeEv+0xf8)[0x1b0c838]
/usr/local/bin/node(_ZN12v8_inspector18V8RuntimeAgentImpl8evaluateERKNS_8String16ESt8optionalIS1_ES4_IbES6_S4_IiES6_S6_S6_S6_S6_S4_IdES6_S6_S6_S5_St10unique_ptrINS_8protocol7Runtime20SerializationOptionsESt14default_deleteISC_EES9_INSB_7Backend16EvaluateCallbackESD_IS_EE+0x211)[0x1b84421]
/usr/local/bin/node(_ZN12v8_inspector8protocol7Runtime20DomainDispatcherImpl8evaluateERKN8v8_crdtp12DispatchableE+0x2a4)[0x1be8ec4]
/usr/local/bin/node(_ZN8v8_crdtp14UberDispatcher14DispatchResult3RunEv+0x1b)[0x1bab71b]
/usr/local/bin/node(_ZN12v8_inspector22V8InspectorSessionImpl23dispatchProtocolMessageENS_10StringViewE+0x1b8)[0x1b71318]
/usr/local/bin/node[0x12542b4]
/usr/local/bin/node[0x12782b1]
/usr/local/bin/node[0x1275f3e]
/usr/local/bin/node[0x12762a3]
/usr/local/bin/node[0x1276c54]
/usr/local/bin/node(_ZN4node11Environment21RunAndClearInterruptsEv+0x148)[0xfe1088]
/usr/local/bin/node[0xfe10f2]
/usr/local/bin/node(_ZN2v88internal7Isolate27InvokeApiInterruptCallbacksEv+0x6a)[0x14f5bca]
/usr/local/bin/node(_ZN2v88internal10StackGuard16HandleInterruptsENS1_14InterruptLevelE+0x12f)[0x151507f]
/usr/local/bin/node(_ZN2v88internal18Runtime_StackGuardEiPmPNS0_7IsolateE+0x8e)[0x1a7a01e]
[0x7d1e17e76636]
Segmentation fault (core dumped)

Additional Information

The user has provided additional information, including the output of find node_modules -iname *.node and which node. The output of node --version is also provided.

Possible Red-Herring

The user has noted that the n npm package may be related to the issue, as the node command changed location and the old location may be remembered in the current shell.

Conclusion

In conclusion, the user is experiencing a segmentation fault (core dumped) error when using native VS Code debugging with recent versions of Node. The issue is not reproducible on the command line, and the user is unable to provide a minimal reproduction repository. The user has provided detailed information about their setup and the steps they have taken to reproduce the issue.

===========================================================

Q: What is a segmentation fault (core dumped) error?

A: A segmentation fault (core dumped) error is a type of error that occurs when a program attempts to access a memory location that it is not allowed to access. This can cause the program to crash and produce a core dump, which is a file that contains the memory state of the program at the time of the crash.

Q: What is the cause of the segmentation fault (core dumped) error in this case?

A: The cause of the segmentation fault (core dumped) error in this case is not immediately clear. However, based on the stacktrace, it appears that the error is related to the segfault-handler module, which is a module that is used to handle segmentation faults in Node.js.

Q: Is the segfault-handler module the cause of the issue?

A: It is possible that the segfault-handler module is the cause of the issue. However, without more information, it is difficult to say for certain. The user has reported that the issue only occurs when using the native debugger, and the same command executed on the command line runs without issues.

Q: What is the relationship between the n npm package and the issue?

A: The n npm package is used to change node versions. The user has reported that when they use n to switch to any version prior to 23.11.0, such as 23.10.0, everything works as expected. This suggests that the issue may be related to the n package or the way it changes node versions.

Q: What can be done to resolve the issue?

A: To resolve the issue, the user may need to try the following:

  • Update to the latest version of Node.js
  • Try using a different version of Node.js
  • Try using a different debugger, such as the Chrome DevTools debugger
  • Try disabling the segfault-handler module
  • Try updating the n package to the latest version

Q: What are some possible causes of the issue?

A: Some possible causes of the issue include:

  • A bug in the segfault-handler module
  • A bug in the n package
  • A bug in the way that Node.js handles segmentation faults
  • A bug in the way that the native debugger interacts with Node.js

Q: How can I troubleshoot the issue further?

A: To troubleshoot the issue further, you can try the following:

  • Enable debugging in Node.js to get more information about the error
  • Use a debugger such as the Chrome DevTools debugger to step through the code and see where the error is occurring
  • Try to reproduce the issue in a minimal reproduction repository
  • Try to identify any patterns or correlations between the issue and other factors, such as the version of Node.js or the version of the n package.

Q: What are some best practices for debugging Node.js applications?

A: Some best practices for debugging Node.js applications include:

  • Using a debugger such as the Chrome DevTools debugger
  • Enabling debugging in Node.js to get more information about the error
  • Using a logging library to log information about the application
  • Using a monitoring tool to monitor the performance of the application
  • Using a testing framework to write unit tests and integration tests for the application.

Q: What are some resources for learning more about debugging Node.js applications?

A: Some resources for learning more about debugging Node.js applications include:

  • The official Node.js documentation on debugging
  • The official Node.js documentation on error handling
  • The official Node.js documentation on logging
  • The official Node.js documentation on monitoring
  • The official Node.js documentation on testing
  • Online courses and tutorials on debugging Node.js applications
  • Online communities and forums for discussing debugging Node.js applications.