Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode stops on invisible breakpoint on "async_hooks.js" while debugging a node.js script

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:

  1. 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?

  2. 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.

  3. 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.

  4. 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.

like image 714
Gibor Avatar asked Aug 05 '19 11:08

Gibor


People also ask

Why is my breakpoint not working Vscode?

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.

Is it possible to set breakpoint in node JS?

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.


1 Answers

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

like image 80
Arsinclair Avatar answered Oct 16 '22 14:10

Arsinclair