Hard crash (of everything) when debugging nodejs #18758

Closed
chadbr opened this Issue Jan 18, 2017 · 30 comments

Projects

None yet

6 participants

@chadbr
chadbr commented Jan 18, 2017 edited
  • VSCode Version: Version 1.8.1 (1.8.1) - ee428b0 - 2016-12-19T14:40:36.266Z
  • OS Version: macos 10.12.2
  • Nodejs version: v6.7.0

Steps to Reproduce:

  1. open code in empty folder
  2. create an app.js with 2 console.writeline() functions
  3. set breakpoints
  4. go to debug pane, accept default setup
  5. press f5 or debug button
  6. when breakpoint is hit, press the stop button

On my colleges machine, vscode crashes. On my machine everything crashes (the shell, all applications, everything...) then the shell restarts.

repo gif attached... you don't see the crash because the app recording the gif gets killed...
crashanim

Anyone else???

@isidorn isidorn was assigned by dbaeumer Jan 19, 2017
@dbaeumer dbaeumer added the debug label Jan 19, 2017
@isidorn
Contributor
isidorn commented Jan 19, 2017

@chadbr I can not reproduce this behavior.

  1. Do you see this all the time
  2. Do you only see this when debugging Javascript or for all languages
  3. Do you also see this when you disable all extensions in vscode
  4. Do you see this with VSCode insiders also

ping @weinand for ideas

@chadbr
chadbr commented Jan 19, 2017

@isidorn

  1. yes, every time.

for my colleague - this just started. He asked me to try to see if I had the same issues.

He rolled back to the previous version of vscode and had the same result.

I haven't debugged any node code in a while -- so I'm not sure when it started on my machine.

  1. only nodejs AFAIK. I debugged both .net core & angular2 tests very recently with no issues.

  2. I'll try this today...

  3. Same results with the insiders build.

@isidorn
Contributor
isidorn commented Jan 19, 2017

@weinand might it be that node-debug somehow terminates vscode by accident

@chadbr since this seems to be happening for your celleague and you (nobody else complained) can you distill what do those two machines have in come. Same node version? Same os version? Something special

@weinand weinand was assigned by isidorn Jan 19, 2017
@chadbr
chadbr commented Jan 19, 2017

@isidorn @weinand

Tried #3 - disabled all plugins - didn't help.

I don't have anything special going on -- typical mac dev box with 500 apps on it :)

I'm happy to let you remote in? or is there some telemetry I can enable or?

@chadbr
chadbr commented Jan 19, 2017

could uninstalling / reinstalling potentially help? any instructions for "cleaning code" from a machine?

I hope to get this working soon - I use code all day every day!

@weinand
Member
weinand commented Jan 19, 2017

Cannot reproduce either.
console does not have a function writeline(), but this doesn't explain the issue you are seeing...

Please add a trace property to your launch config like this:

		{
			"type": "node",
			"request": "launch",
			"name": "Launch Program",
			"program": "${workspaceRoot}/test.js",
			"cwd": "${workspaceRoot}",
			"trace": "all"
		}

and post the resulting debug console output here.

@weinand
Member
weinand commented Jan 19, 2017

What happens if you do not press the 'terminate' button but the green 'continue' (play) button instead?

@chadbr
chadbr commented Jan 19, 2017

if I press pause it crashes - let me play with above -

@weinand
Member
weinand commented Jan 19, 2017

Please try our experimental node2 debugger by changing the value of the type attribute in your launch config to node2. Do you see the same behaviour?

@weinand
Member
weinand commented Jan 19, 2017 edited

More things you can try (only one at a time):

  • reboot your Mac
  • install a different version of node, e.g. 6.5
  • open the "Console" application and then watch out for any suspicious entries that appear when pressing the 'terminate' button in VS Code.
@weinand
Member
weinand commented Jan 19, 2017

Inside the VS Code app is a script "terminateProcess.sh" in "/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug/out/node/terminateProcess.sh"
This scripts uses the pgrep command. Do you have a different pgrep command installed on your system?
If you don't know you could rename the "terminateProcess.sh" temporarily so that VS Code will not find it any more. Does the crash still occur?

@chadbr
chadbr commented Jan 19, 2017 edited

@weinand wow - that fixed it --

I did this:
Chads-MacBook-Pro:Github chadbr$ mv /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug/out/node/terminateProcess.sh /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug/out/node/SAVE-terminateProcess.sh

  • here's the contents if it helps

#!/bin/bash

terminateTree() {
for cpid in $(pgrep -P $1); do
terminateTree $cpid
done
kill -9 $1 > /dev/null 2>&1
}

for pid in $*; do
terminateTree $pid
done

@chadbr
chadbr commented Jan 19, 2017

should I try any of the others?

@weinand
Member
weinand commented Jan 19, 2017

@chadbr no, it seems that you found the culprit.
Now the question is why does it behave like this on your system?
Please type which pgrep in a terminal. What is the resulting path?

@chadbr
chadbr commented Jan 19, 2017

@weinand
$ which pgrep
/usr/local/bin/pgrep

@weinand
Member
weinand commented Jan 19, 2017

Aha, the pgrep on my Mac lives at /usr/bin/pgrep.
So you seem to have a different version (and VS Code seems to call the wrong one which is clearly a bug on our side).

@lucas-natraj
lucas-natraj commented Jan 19, 2017 edited

This was happening to me (#14187) although it only killed vscode.
On clicking the 'stop' it would take ~12 seconds and then vscode would crash.
I wiped node, nvm, all node_modules, node_gyp, vscode and extensions, then restarted my machine and reinstalled everything (except the extensions).
It still takes ages to stop debugging but at least it doesn't seem to kill vscode anymore.

With the 'trace' line in the launch config the time appears to be spent at

...
shutdown: kill debugee and sub-processes
----------  *** Waits really long here *** ----------
disconnectRequest: send response
_terminated: socket end
_terminated: node v8protocol close
@weinand
Member
weinand commented Jan 19, 2017

@lucas-natraj what is the path to your pgrep?

@lucas-natraj
lucas-natraj commented Jan 19, 2017 edited

Same as @chadbr
/usr/local/bin/pgrep

@weinand
Member
weinand commented Jan 19, 2017

Do you know what this /usr/local/bin/pgrep really is?

@lucas-natraj
lucas-natraj commented Jan 19, 2017 edited

/usr/local/bin/pgrep -> /usr/local/Cellar/proctools/0.4pre1/bin/pgrep

@weinand
Member
weinand commented Jan 19, 2017

Could you try to change the pgrep in the "terminateProcess.sh" in "/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug/out/node/terminateProcess.sh" to /usr/bin/pgrep and check whether this makes a difference?

@weinand weinand added bug important and removed needs more info labels Jan 19, 2017
@weinand weinand added this to the January 2017 milestone Jan 19, 2017
@isidorn isidorn was unassigned by weinand Jan 19, 2017
@lucas-natraj

That seemed to fix it. Stops debugging immediately!

...Happiness...

Gratitudes!!

@weinand
Member
weinand commented Jan 19, 2017

@lucas-natraj @chadbr thanks a lot for helping with the investigation!

@weinand
Member
weinand commented Jan 19, 2017

I can easily reproduce the problem after running this brew install proctools

@lucas-natraj

Good to hear.
Am curious to know why it was previously delaying and then crashing vscode, but after the reinstall only the delay remained.

@weinand
Member
weinand commented Jan 19, 2017 edited

pgrep is used to find all sub-processes launched by the debug target. For a simple node program it should not find any sub-processes.

So if I launch node and then do a ps to find its process ID (e.g. 36915) and then use /usr/bin/pgrep -P 36915 no process IDs are listed. This is the correct behaviour.

If I use the pgrep installed by brew I get a list of 456 process IDs. This doesn't seem right. So either brew's pgrep is broken or the semantics of the -Poption is different.

The "terminateProcess.sh" script then tries to kill all those processes (which takes a long time and most kills will fail due to missing permissions).

@lucas-natraj

Cool. That explains the delay.
Was the crash occurring because of the missing kill permission? Or something else?

@weinand
Member
weinand commented Jan 19, 2017 edited

The crash of VS Code or the Finder etc. occurs because brew's pgrep returns the process IDs of many (if not all) processes and the script tries to kill them all. I really mean all macOS processes!

The -P option should filter this list to only those processes that are child processes of the specified process. But this filter doesn't work for brew's pgrep command.

@weinand weinand added a commit to Microsoft/vscode-node-debug that closed this issue Jan 19, 2017
@weinand weinand always use the correct pgrep; fixes Microsoft/vscode#18758 45d3fce
@weinand
Member
weinand commented Jan 19, 2017

Fixed in tomorrows Insiders build

@roblourens roblourens added a commit to Microsoft/vscode-node-debug2 that referenced this issue Jan 20, 2017
@roblourens roblourens Copy vscode-node-debug fix for Microsoft/vscode#18758 4578b58
@roblourens roblourens added the verified label Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment