apache/openwhisk-wskdebug

wskdebug does not work with new vs code debugger

alexkli opened this issue ยท 9 comments


Update: Solution ๐ŸŽ‰

If you are coming here from the warning given by wskdebug WARNING: wskdebug itself is debugged and likely NOT the action, then you have to update your VS Code launch config.

Starting with VS Code 1.48+ these settings are required to work with wskdebug:

            "type": "pwa-node",
            "request": "launch",
            "attachSimplePort": 0,
            "killBehavior": "polite",

Here is a complete example - adjust the args and name as needed:

    "configurations": [
        {
            "name": "wskdebug MYACTION", // <-- adjust name for debug drop-down
            "type": "pwa-node",
            "request": "launch",
            "attachSimplePort": 0,
            "killBehavior": "polite",
            "runtimeExecutable": "wskdebug",
            "args": [
                "MYACTION",  // <-- replace with name of the action
                "ACTION.js", // <-- replace with local path to action source file
                "--cleanup", // remove helper actions on shutdown
                "-l",        // enable live-reload
                "-v"         // log parameters and results
            ],
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/code",
            "outputCapture": "std"
        }
    ]

This is also documented here: https://github.com/apache/openwhisk-wskdebug#nodejs-visual-studio-code


.
.
.

Original issue:

Problem

The new VS code debugger recently released (?) no longer sets --inspect-brk=XXXX for the debug port which wskdebug can intercept, but instead sets a NODE_OPTIONS with a custom --require that loads a (large) VS code javascript file into the process which apparently sets up debugging internally. This leads to the wskdebug node process itself being debugged, not the actual action on the container.

Links

โ–ถ๏ธ Solutions โ—€๏ธ

Collecting all solutions here, will be kept updated.

Quick Workaround

Simple workaround for now: Disable the new debugger in VS Code by setting this in the user settings json:

"debug.javascript.usePreview": false

This will work as long as VS Code supports this feature.

Future fix

The new VS Code debugger will get some changes that make it work with wskdebug. To get a preview, one has to install the VS code debugger nightly. Do this at your own risk.

  1. install nightly of debugger plugin (after July 16)
  2. in launch config have this:
    {
       "type": "pwa-node", // important
       "request": "launch",
       "name": "wskdebug",
       "attachSimplePort": 0, // instead of "port", makes it auto-select a free debug port
  3. use latest wskdebug 1.3.0 RC. install the pre-release from github directly:
    npm install -g https://github.com/apache/openwhisk-wskdebug
    

Fix with new vs code debugger nightly

  1. install nightly of debugger plugin (after July 16 evening PST)
  2. in launch config have this:
    {
       "type": "pwa-node", // important
       "request": "launch",
       "name": "wskdebug",
       "attachSimplePort": 0, // instead of "port", makes it auto-select a free debug port
       "killBehavior": "polite"

Problem: requires to hardcode the port number. See microsoft/vscode-js-debug#630 (comment)

An initial improvement is in for the upcoming 1.3 release (detect problematic case & warn user, updated documentation). Keeping this issue open to track the changes on the VS code side and make any updates to the code or in documentation once those are released.

VS Code July 2020 release (1.48.x) includes the necessary changes enabling use of wskdebug with the new debugger, except for proper shutdown handling microsoft/vscode-js-debug#630. We could update the documentation accordingly now.

@alexkli so to be clear, VS Code 1.48.x does NOT need this fix, and the wskdebug module (v1.3.0) available on npmjs today will work with VSCode 1.48.x (other than the inability to exit the debugger process)

@davidjgonzalez with VS Code 1.48.x you have to use a different config in launch.json than before to make it work. see above: #74 (comment)

so would a 1.48.x compat launch.json look like:

{
    "type": "pwa-node",
    "request": "launch",
    "name": "wskdebug",
    "attachSimplePort": 0,
    "runtimeExecutable": "wskdebug",
    "args": [
        "foo-0.0.1/__secured_worker",  
        "${workspaceFolder}/actions/worker/index.js",  
        "-l",
        "--ngrok"
    ],
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/code",
    "outputCapture": "std",
    "timeout": 30000
}

Im not sure where the your example snippet in #74 (comment) "ends" and the "normal" config resumes for it to work properly.

@davidjgonzalez I believe so, but we'll provide updated documentation soon. this has to be tested first (I haven't tested anything with 1.48.x yet, only with that older nightly from some weeks ago).

For now the simplest as end user is to use the "debug.javascript.usePreview": false workaround.

VS Code now supports "killBehavior": "polite" to get SIGTERM to work again: microsoft/vscode-js-debug#630 (comment)

Need to test this and document.

The new launch config works fine. Documentation update in #82.