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

seeking feedback: debugging-aid #324

Closed
naugtur opened this issue Aug 24, 2019 · 9 comments
Closed

seeking feedback: debugging-aid #324

naugtur opened this issue Aug 24, 2019 · 9 comments
Labels

Comments

@naugtur
Copy link
Contributor

naugtur commented Aug 24, 2019

I'm experimenting with possible ways of debugging and would like to discuss their usefulness and validity.

https://github.com/naugtur/debugging-aid

The tools use not-so-well-known features of Node.js to help figure out common problems.

  • promises: global promise issues handlers are fairly obvious to everyone here, it just logs them
  • blocked: blocked-at has already been discussed here somewhere I think. It uses async hooks to get a stack trace pointing to the blocking function
  • network: network tab in debugger is something I've always wanted, this is the closest thing
  • moduse: adds a getter/setter on Module._cache for a given id and uses that to track where it was required. I wonder if require checking the cache for built-in modules as well is something I can rely on. Got the idea for this when wondering how to detect if a malicious library loads net to call home.
@mhdawson
Copy link
Member

@naugtur would it make sense for you to give a presentation/walk through these tools in a Diagnostics WG meeting?

@naugtur
Copy link
Contributor Author

naugtur commented Aug 27, 2019

As long as it's the one tomorrow, I can do it.

@mhdawson
Copy link
Member

@hekike can you add to the agenda for tomorrow?

@naugtur
Copy link
Contributor Author

naugtur commented Sep 3, 2019

I presented this at the recent Diagnostics WG meeting and had some questions. People suggested I ask @mcollina these two:

TL;DR bolded

1. One of my experiments (moduse.js) hooks into Module._cache with a getter and setter and prints stack traces leading to each place in the codebase where a certain module is required. I built it for the specific purpose of finding out which packages are requiring the 'net' or 'http' internal modules.

I was surprised it actually works that way - when you require('net') cache is checked even though it's a built-in module and the cache is never populated.

Is that desired behavior for some obvious reason I'm missing? I'm considering adding a PR with a test that would assert this and asking if the assertion should require or forbid this behavior. The tests for module loading I found didn't cover this case.

2. Another experiment is using perf tracing for output. This question is rather simple.
Is there a way to get node_trace.1.log to get written without performing a graceful shutdown? Can I trigger writing it?

I've rarely seen http servers written in Node.js with logic to gracefully shutdown by closing the sockets and removing all intervals.
There might be a threshold of content at which the file is written while the process is still running, but what if I'm running it locally and there's very little output?

I'm offering to turn the answers I get into documentation ;)

@mcollina
Copy link
Member

mcollina commented Sep 4, 2019

  1. One of my experiments (moduse.js) hooks into Module._cache with a getter and setter and prints stack traces leading to each place in the codebase where a certain module is required. I built it for the specific purpose of finding out which packages are requiring the 'net' or 'http' internal modules.

I was surprised it actually works that way - when you require('net') cache is checked even though it's a built-in module and the cache is never populated.

Some modules (https://www.npmjs.com/package/proxyquire) use that mechanism to intercept module loading to place mocks.

Is there a way to get node_trace.1.log to get written without performing a graceful shutdown? Can I trigger writing it?

I do not know the answer to this.

@vmarchaud
Copy link
Contributor

vmarchaud commented Sep 4, 2019

Is there a way to get node_trace.1.log to get written without performing a graceful shutdown? Can I trigger writing it?

You can use the inspector module, i've a working implementation here.
If you are interested in a minimum sample, look at this unit test.

@quantuminformation
Copy link

Any video demos of this? Just want the network tab.

@naugtur
Copy link
Contributor Author

naugtur commented Sep 11, 2019

@vmarchaud thanks, will check it out.
@quantuminformation I demoed this on a Diag WG meeting before posting this thread and the recording should be in the archive, but you'll save a lot of time by reading the readme on the repo and just trying it out. It prints to standard output. You'll see.

@github-actions
Copy link

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants