Skip to content

Segmentation fault: 11 when debug Promise #4577

Description

@3y3

Segfault happens when I try to use evaluate command in non stopped process, which logs Promise to console.
node - latest 4 and 5
os - darwin x64

app.js

setInterval(console.log, 100, new Promise(() => {}));

pseudo debugger:

require('net').connect('5858', function() {
  var data = JSON.stringify({
    "seq": 1,
    "type": "request",
    "command": "evaluate",
    "arguments": {
      "global": true,
      "expression": "global"
    }
  });

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

All works fine if process is paused or I don't try to log Promise:

setInterval(() => {
  var p = new Promise(() => {});
  console.log(''); // works fine
}, 100)

Encapsulated test:

var app = require('child_process')
  .exec('node --debug -e "setInterval(console.log, 10, new Promise(() => {}))"')
  .on('exit', () => console.assert(app.signalCode !== 'SIGSEGV', 'Segmentation fault'));

app.stderr.on('data', () => /* wait for `Debugger listening on port 5858`*/
  setTimeout(() =>
    require('net').connect('5858', function() {
      var data = JSON.stringify({
        "seq": 1,
        "type": "request",
        "command": "evaluate",
        "arguments": {
          "global": true,
          "expression": "global" /* global is accessible in global scope */
        }
      });

      this.write(`Content-Length: ${Buffer.byteLength(data, 'utf8')}\r\n\r\n${data}`);
    }), 300 /* small delay to initialize debugger in app */));

Activity

  1. mscdex commented on Jan 8, 2016

    @mscdex
    Contributor

    "node - latest 4 and 5" Can you be more specific about the exact versions you tried? 5.4.0 was just released the other day. Did you also try with the latest master branch?

  2. davidvgalbraith commented on Jan 8, 2016

    @davidvgalbraith

    I just tried the latest master branch -- can confirm segfault.

  3. davidvgalbraith commented on Jan 8, 2016

    @davidvgalbraith

    Ah, sorry, the line .exec('node --debug -e "setInterval(console.log, 10, new Promise(() => {}))"') ran my global node which is behind master. Does not segfault when I replace that node with ./node, so I think this duplicates #4261.

  4. mscdex commented on Jan 8, 2016

    @mscdex
    Contributor

    I was able to duplicate it on OS X 10.10 with node v5.3.0, but not with v5.4.0.

    Can you confirm @davidvgalbraith @3y3 ?

  5. davidvgalbraith commented on Jan 8, 2016

    @davidvgalbraith

    I'm seeing the same thing @mscdex

  6. 3y3 commented on Jan 8, 2016

    @3y3
    Author

    Ok, sorry, I miss release of 5.4. I can't confirm segfault on 5.4, but code doesn't work correctly:
    I add console.log for response from app. I expect two messages:
    connection info

    Type: connect
    V8-Version: 4.6.85.31
    Protocol-Version: 1
    Embedding-Host: node v5.4.0
    Content-Length: 0
    

    and evaluation result, but I receive only connection info.

    var app = require('child_process')
      .exec('node --debug -e "setInterval(console.log, 10, Promise.all())"')
      .on('exit', () => console.log(app, app.signalCode !== 'SIGSEGV', 'Segmentation fault'));
    
    app.stderr.on('data', () =>
      setTimeout(() =>
        require('net').connect('5858', function() {
          var data = JSON.stringify({
            "seq": 1,
            "type": "request",
            "command": "evaluate",
            "arguments": {
              "global": true,
              "expression": "global" /* global is accessible in global scope */
            }
          });
    
          this.on('data', (data) => console.log('' + data));
    
          this.write(`Content-Length: ${Buffer.byteLength(data, 'utf8')}\r\n\r\n${data}`);
    
        }), 300 /* small delay to initialize debugger in app */));
  7. 3y3 commented on Jan 8, 2016

    @3y3
    Author

    @davidvgalbraith, @mscdex, is there any changes in debugger protocol in 5.4?

    Is it possible to backport segfault fix in v4?

  8. 3y3 commented on Jan 8, 2016

    @3y3
    Author

    I also see the difference in debugger statement behavior (difference between 0.10 and latest versions)
    In latest versions debugger pauses program if it was started with --debug flag. In 0.10 this happens only in there exists connected debugger.
    Is it expected behavior @indutny ?

  9. mscdex commented on Jan 8, 2016

    @mscdex
    Contributor

    @3y3 #4328 is already tagged for potential inclusion in v4.x.

  10. 3y3 commented on Jan 8, 2016

    @3y3
    Author

    Ok, I'm ready to close this issue and open one other about stalled debugger #4577 (comment)
    Or I can rename this issue.

  11. mscdex commented on Jan 8, 2016

    @mscdex
    Contributor

    @3y3 I would probably open a new issue and close this one.

  12. 3y3 commented on Jan 9, 2016

    @3y3
    Author

    Ready #4597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions