Skip to content

Capture stack trace from main thread #58238

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

Open
timfish opened this issue May 8, 2025 · 0 comments
Open

Capture stack trace from main thread #58238

timfish opened this issue May 8, 2025 · 0 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@timfish
Copy link
Contributor

timfish commented May 8, 2025

What is the problem this feature will solve?

If synchronous user code blocks the event loop for an extended or indefinite period of time, it would be useful to be able to capture a stack trace to help fix the issue.

Preferably we should be able to capture a stack trace for the main thread from a worker thread so this can be handled in JavaScript.

What is the feature you are proposing to solve the problem?

Improve the diagnostic report feature?

What alternatives have you considered?

Inspector API

You can pause and capture stack traces via the inspector API but it's often not suitable for production usage.

  • Debugger can impact performance
  • It's not trivial to convert inspector stack frames to the error.stack format
  • Serverless embedders can build node without inspector support (Vercel but probably others too!)
  • Enabling Node debugger in production has potential security issues

Diagnostic report API

The diagnostic report is almost there but it has a few issues:

  • When this feature was brought into core, it didn't retain the watchdog thread that allowed it to interrupt via signal and capture a stack trace from the main thread. The signal handling is now in JavaScript so it is only called if or when the event loop becomes unblocked, by which time the call stack is not relevant. Does anyone have context as to why it was done this way?
  • Report is only to file or stdout 😢

The diagnostic report does collect stack traces from worker threads because it interrupts them.

@timfish timfish added the feature request Issues that request new features to be added to Node.js. label May 8, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

1 participant