Oryx icon indicating copy to clipboard operation
Oryx copied to clipboard

Node.js remote debugging doesn't work when using yarn

Open GyroJoe opened this issue 4 years ago • 0 comments

Bug Report

(Apologies if this is the wrong location to report this issue, it seems to be where the startup script is that configures this process)

  • At what date and time did you most recently experience the problem?

2021-10-07T22:20:11.751358742Z

  • Where did you experience the problem? E.g. Azure Web Apps, Azure Functions, Azure Container Registry, or offline use.

Azure App Service

  • If your repo is publicly available please share its URL:

Not public (MS internal, can provide details if needed)

  • What happened?

When enabling Node.js remote debugging when using yarn (via the Azure VSCode extension) , the yarn process gets started under the debugger rather than the main app.

ps ax output looks like this:

   27 ?        SN     0:00 /bin/sh /opt/node-wrapper//node /opt/yarn-v1.17.3/bin/yarn.js run start
   38 ?        SNl    0:00 /usr/local/bin/node --inspect=0.0.0.0:49494 /opt/yarn-v1.17.3/bin/yarn.js run start
   50 ?        SN     0:00 /bin/sh -c node --max-http-header-size=32768 dist/index.js
   51 ?        SNl    0:03 /usr/local/bin/node --max-http-header-size=32768 dist/index.js

It seems like node-wrapper should also exclude /opt/ in addition to /usr/local/. I'm unsure if this will fully resolve the problem, since yarn appears to be very opinionated about which node it will run - see: https://github.com/yarnpkg/yarn/issues/7195#issuecomment-485071220.

Yarn launches node directly from whatever binary launches yarn itself: https://github.com/yarnpkg/yarn/blob/3119382885ea373d3c13d6a846de743eca8c914b/src/cli/commands/node.js

There's a NODE_OPTIONS env var here, maybe that could work?

Failing to attach would still be a better outcome than what's happening now however.

  • What did you expect or want to happen?

The main node process is setup for remote debugging, not yarn. By renaming the yarn.lock file I can trick the startup script into using npm instead, which works (I understand there are other startup options, like pm2 as well).

ps ax output then looks like this and debugging works:

   27 ?        SN     0:00 /bin/sh /opt/node-wrapper//node /usr/local/bin/npm start --scripts-prepend-node-path false
   28 ?        SNl    0:00 npm
   46 ?        SN     0:00 sh -c node --max-http-header-size=32768 dist/index.js
   47 ?        SN     0:00 /bin/sh /opt/node-wrapper//node --max-http-header-size=32768 dist/index.js
   48 ?        SNl    0:03 /usr/local/bin/node --inspect=0.0.0.0:49494 --max-http-header-size=32768 dist/index.js
  • How can we reproduce it?

Create a simple Node web app using yarn with a start script in package.json. Deploy it to an Azure App Service. Try to start remote debugging.

  • Do you have log output? Please include between the backticks:

From docker:

2021-10-07T22:20:11.751358742Z   _____                               
2021-10-07T22:20:11.751387443Z   /  _  \ __________ _________   ____  
2021-10-07T22:20:11.751392144Z  /  /_\  \___   /  |  \_  __ \_/ __ \ 
2021-10-07T22:20:11.751396044Z /    |    \/    /|  |  /|  | \/\  ___/ 
2021-10-07T22:20:11.751399644Z \____|__  /_____ \____/ |__|    \___  >
2021-10-07T22:20:11.751409444Z         \/      \/                  \/ 
2021-10-07T22:20:11.751413444Z A P P   S E R V I C E   O N   L I N U X
2021-10-07T22:20:11.751416845Z 
2021-10-07T22:20:11.751420045Z Documentation: http://aka.ms/webapp-linux
2021-10-07T22:20:11.751423445Z NodeJS quickstart: https://aka.ms/node-qs
2021-10-07T22:20:11.751426845Z NodeJS Version : v14.15.1
2021-10-07T22:20:11.751430245Z Note: Any data outside '/home' is not persisted
2021-10-07T22:20:11.751433845Z 
2021-10-07T22:20:11.998716072Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2021-10-07T22:20:12.007503378Z Could not find operation ID in manifest. Generating an operation id...
2021-10-07T22:20:12.008101206Z Build Operation ID: 0628edbe-9a2f-4f79-8a4e-910159500d10
2021-10-07T22:20:12.936424602Z Environment Variables for Application Insight's IPA Codeless Configuration exists..
2021-10-07T22:20:13.611121778Z Writing output script to '/opt/startup/startup.sh'
2021-10-07T22:20:14.076444580Z Running #!/bin/sh
2021-10-07T22:20:14.076465481Z 
2021-10-07T22:20:14.076470681Z # Enter the source directory to make sure the script runs where the user expects
2021-10-07T22:20:14.076474981Z cd "/home/site/wwwroot"
2021-10-07T22:20:14.076478981Z 
2021-10-07T22:20:14.076482882Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2021-10-07T22:20:14.076486882Z if [ -z "$PORT" ]; then
2021-10-07T22:20:14.076490782Z 		export PORT=8080
2021-10-07T22:20:14.076494682Z fi
2021-10-07T22:20:14.076503883Z 
2021-10-07T22:20:14.076507783Z export PATH=/opt/node-wrapper/:$PATH
2021-10-07T22:20:14.076511583Z export ORYX_NODE_INSPECT_PARAM="--inspect=0.0.0.0:49494"
2021-10-07T22:20:14.076515383Z yarn run start
2021-10-07T22:20:14.166668749Z Debugger listening on ws://0.0.0.0:49494/d2ee529e-4448-467e-942b-e34c7dc2df41
2021-10-07T22:20:14.167901106Z For help, see: https://nodejs.org/en/docs/inspector
2021-10-07T22:20:14.596969932Z yarn run v1.17.3
2021-10-07T22:20:14.657928649Z $ node --max-http-header-size=32768 dist/index.js

From the VSCode (confirming that yarn gets debugged, not the app itself):

Could not read source map for file:///opt/yarn-v1.17.3/lib/cli.js: ENOENT: no such file or directory, open '/opt/yarn-v1.17.3/lib/toSubscriber.js.map'

GyroJoe avatar Oct 07 '21 22:10 GyroJoe