so I built a script in node.js which supposed to take csv files, parse them and enter them to DB. Sometimes, when I debug my code, it stops on like an invisible breakpoint found in async_hooks.js file, on the first line of the "emitHookFactory" function (line 163).
The call stack states only one call- "emitBeforeNative" on the same file.
I noticed a few things on my trials:
I have 3 types of files I need to parse and put in the DB. It happens only on one of the file types, which is extremely large (3.1m~ lines on csv, while the others have 50~200K lines). I tried to load it partially- only the starting 20K lines (copied them to a new file, no changes in code) and it didn't break. which means the size has to do with the debugger stopping?
I tried to reproduce it with other means but no success. Also, it doesn't happen always (even when ran on the same file)- but like 80-85% of the times.
My script goes like this: query DB and AWS to find a new file > download file to local > stream the file from local > on line
event- parse line and perform data manipulations > on end
event - loop through all manipulated data, build queries and query the DB to insert it. I've put a few breakpoints on key places and found out the breakpoint SEEMS to happen somewhere in the middle of emitting the line
events. The callback function is a normal function, not async, and there are no async operations inside. In fact, there are only array and string manipulations operations inside- not even 3rd party operation or anything unusual.
I tried to look at the internet for solution. Didn't find any clear way to comletely get rid of it, only workaround which I didn't really understand (kinda new to JS environments so I could not get the concepts of how can I disable or ignore it...)
Thanks for the help in advanced.
If a source file has changed and the source no longer matches the code you're debugging, the debugger won't set breakpoints in the code by default. Normally, this problem happens when a source file is changed, but the source code wasn't rebuilt. To fix this issue, rebuild the project.
When debugging in Node. js, we add a breakpoint by adding the debugger keyword directly to our code. We can then go from one breakpoint to the next by pressing c in the debugger console instead of n . At each breakpoint, we can set up watchers for expressions of interest.
Based on https://github.com/nodejs/node/issues/15464
There's a way to ignore stepping into Node guts. In your launch.json add the following skipFiles directive:
"skipFiles": [
"<node_internals>/**"
]
or you can ignore particularly /internal/async_hooks
with this:
"skipFiles": [
"<node_internals>/internal/async_hooks.js",
"<node_internals>/internal/inspector_async_hook.js"
]
After all, your config may look like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Debug",
"runtimeExecutable": "<your executable path>",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"timeout": 30000,
"skipFiles": [
"<node_internals>/**"
]
}
]
}
This also might be related to a known NodeJS bug: https://github.com/nodejs/node/issues/36022
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With