Gibor
Gibor

Reputation: 1721

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.

Upvotes: 15

Views: 3737

Answers (2)

Raman Sinclair
Raman Sinclair

Reputation: 1283

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

Upvotes: 13

Andre Weinand
Andre Weinand

Reputation: 1977

Could you please try whether our new JavaScript debugger still has this problem. For details see the release notes of VS Code 1.42: https://code.visualstudio.com/updates/v1_42#_new-javascript-debugger.

Upvotes: -1

Related Questions