Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger protocol hangs in some special situations #4597

Closed
3y3 opened this issue Jan 9, 2016 · 12 comments
Closed

Debugger protocol hangs in some special situations #4597

3y3 opened this issue Jan 9, 2016 · 12 comments
Assignees

Comments

@3y3
Copy link

3y3 commented Jan 9, 2016

This test fails because we don't receive nothing except first startup message

var app = require('child_process')
  .exec('node --debug -e "setInterval(console.log, 10, {a: 1})"');

app.stderr.on('data', () =>
  setTimeout(() =>
    require('net').connect('5858', function() {
      var buffer = '';
      var data = JSON.stringify({
        "seq":2,
        "type":"request",
        "command":"evaluate",
        "arguments":{
          "expression":"1",
          "global":true,
          "maxStringLength":-1
        }});

      this.on('data', (data) => buffer += data);

      this.write(`Content-Length: ${Buffer.byteLength(data, 'utf8')}\r\n\r\n${data}`);

      setTimeout(() => {
        var cl = 0;
        var rx = /Content-Length/g;

        // We wait two messages - startup and evaluation response
        // We wait two Content-Length heades - one for each message
        while (rx.exec(buffer)) cl++;
        console.assert(cl == 2, 'There is no second message');
        console.log('All works fine');
        process.exit(0);
      }, 300)
    }), 300 /* small delay to initialize debugger in app */));

But if I change console.log arguments in line 2 - all works fine:

var app = require('child_process')
  .exec('node --debug -e "setInterval(console.log, 10, 1)"');

app.stderr.on('data', () =>
  setTimeout(() =>
    require('net').connect('5858', function() {
      var buffer = '';
      var data = JSON.stringify({
        "seq":2,
        "type":"request",
        "command":"evaluate",
        "arguments":{
          "expression":"1",
          "global":true,
          "maxStringLength":-1
        }});

      this.on('data', (data) => buffer += data);

      this.write(`Content-Length: ${Buffer.byteLength(data, 'utf8')}\r\n\r\n${data}`);

      setTimeout(() => {
        var cl = 0;
        var rx = /Content-Length/g;

        // We wait two messages - startup and evaluation response
        // We wait two Content-Length heades - one for each message
        while (rx.exec(buffer)) cl++;
        console.assert(cl == 2, 'There is no second message');
        console.log('All works fine');
        process.exit(0);
      }, 300)
    }), 300 /* small delay to initialize debugger in app */));
@3y3 3y3 changed the title Debugger protocol steels in some special situations Debugger protocol hangs in some special situations Jan 9, 2016
@mscdex mscdex added the debugger label Jan 9, 2016
@3y3
Copy link
Author

3y3 commented Jan 9, 2016

This is issue for node 5.4

@dan-tull
Copy link

I found this issue because I was seeing frequent crashes of node when trying to debug, which I took to be this issue: #4322

Originally, I was using 5.3.0 (latest from homebrew) and can confirm it also happens in 4.2.6 (the current node4-lts version, also via homebrew).

I cherry-picked only the small applied fix for the segfaults: #4328 onto a checkout of the 4.2.6 branch and now I get the symptoms from this issue instead (my debugger hangs frequently instead of crashing frequently).

I haven't waded into the debugging protocol code yet, but my current suspicion is that the early return added to dodge the segfault is causing the hangs. Previously, the Agent::MessageHandler always took a message and enqueued a new message, but now it sometimes does nothing, which definitely sounds like the kind of change that could cause a hang (a message to which no response is sent).

It may also be at the root of this issue: #4651, but I haven't tried a before/after test with the segfault fix above for that, yet.

@MylesBorins
Copy link
Contributor

perhaps the fix in #4819 might help with this

@MylesBorins
Copy link
Contributor

@3y3 I am so happy!!! It looks like my fix at #4819 fixes the problem you are having. I was struggling to figure out how to write a test for the regression, but your example works! Going to add the test now so we can get the problem fixed. Would you like to be added as the author of this test?

@dan-tull
Copy link

@thealphanerd Just as added confirmation, if I also apply your commit in #4819 to my v4.2.6 branch and rebuild, I can successfully debug the code that originally was crashing and later hanging.

I don't know how much longer the 4.2.x branch is slated to live, but those two patches seem like candidates for inclusion in the next dot.

Thanks! It's great to have debugging more stable again.

@MylesBorins
Copy link
Contributor

@dan-tull I've added 25776f3 to the v4.x-staging branch

Once the other PR has a working test and is landed on master we'll get the backport going

@MylesBorins MylesBorins self-assigned this Jan 27, 2016
@MylesBorins
Copy link
Contributor

@3y3 I ended up having to do quite a bit of modifications to get the test in a place where I felt it was ready to be submitted to core. For now I'm going to squash it into my existed PR to minimize the number of commits (easier to backport). Let me know if you have a problem with that.

@dan-tull
Copy link

@thealphanerd One update: it was nagging me that I hadn't ever tested your "do not incept debug context" change in isolation, so I made a new v4.2.6 branch, built and reproduced the crash, then applied just your fix and rebuilt. It neither crashed nor hung, so the original nullptr check to dodge the crash does not appear to be necessary.

I don't know if there are other cases it fixes, but it might even be worth backing it out so that if a null environment slips through again, it'll fail noisily.

@3y3
Copy link
Author

3y3 commented Jan 27, 2016

@thealphanerd , thank you for fixing this bug! I'm not pretend to be author of test.
Is there any discussions about debugger stability?
For example there is my old pr #1977 with links to original issues.
Would be nice to actualize information about this bugs. I also can actualize my pr.

@MylesBorins
Copy link
Contributor

The fix is now in master, you should expect this to see it in a release in the next 2 - 3 weeks on v4 and v5.

rvagg pushed a commit that referenced this issue Feb 8, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in #4815

Fixes: #4440
Fixes: #4815
Fixes: #4597
Fixes: #4952

PR-URL: #4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
rvagg pushed a commit that referenced this issue Feb 9, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in #4815

Fixes: #4440
Fixes: #4815
Fixes: #4597
Fixes: #4952

PR-URL: #4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins
Copy link
Contributor

The fix is now released in v5.6.0. Expect LTS next week

MylesBorins pushed a commit that referenced this issue Feb 11, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in #4815

Fixes: #4440
Fixes: #4815
Fixes: #4597
Fixes: #4952

PR-URL: #4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit to MylesBorins/node that referenced this issue Feb 11, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in nodejs#4815

Fixes: nodejs#4440
Fixes: nodejs#4815
Fixes: nodejs#4597
Fixes: nodejs#4952

PR-URL: nodejs#4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit to MylesBorins/node that referenced this issue Feb 13, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in nodejs#4815

Fixes: nodejs#4440
Fixes: nodejs#4815
Fixes: nodejs#4597
Fixes: nodejs#4952

PR-URL: nodejs#4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
MylesBorins pushed a commit to MylesBorins/node that referenced this issue Feb 15, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in nodejs#4815

Fixes: nodejs#4440
Fixes: nodejs#4815
Fixes: nodejs#4597
Fixes: nodejs#4952

PR-URL: nodejs#4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@MylesBorins
Copy link
Contributor

The fix is now in lts on v4.3.1 !

scovetta pushed a commit to scovetta/node that referenced this issue Apr 2, 2016
Currently a debug context is created for various calls to util.

If the node debugger is being run the main context is the debug
context. In this case node_contextify was freeing the debug context
and causing everything to explode.

This change moves around the logic and no longer frees the context.

There is a concern about the dangling pointer

The regression test was adapted from code submitted by @3y3 in nodejs#4815

Fixes: nodejs#4440
Fixes: nodejs#4815
Fixes: nodejs#4597
Fixes: nodejs#4952

PR-URL: nodejs#4815

Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants