Skip to content

res.send cause process exit without a catchable exception #2836

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

Closed
calidion opened this issue Dec 29, 2015 · 9 comments
Closed

res.send cause process exit without a catchable exception #2836

calidion opened this issue Dec 29, 2015 · 9 comments
Assignees

Comments

@calidion
Copy link

I have encountered process exit with res.send which will not throw any exception when the res has been terminated by the peer server.
this can be reproduce again and again.
if i comment res.send, then the node process won't exit anymore.

@brandonburkett
Copy link

I am having this issue as well with node 5.3 and express 4.13.3

return res.status(err.status || 500).send((['development'].indexOf(process.env.NODE_ENV) !== -1) ? err : {message: 'something went wrong'});

Process finished with exit code 139
Segmentation fault: 11

@dougwilson
Copy link
Contributor

Hi you guys. Unfortunately trying that code snippet does not cause the app to exit for me. In order for us to take a look, please provide the following information:

  1. What exact version of express are you using?
  2. What exact version of Node.js are you using?
  3. A full app we can copy and paste into a file and run that reproduces the issue.
  4. The request to make to the app to reproduce the issue.

Without us being able to reproduce the issue or you providing a stack trace of an error, we would have to wait for you to provide a pull request to fix the issue, if there is an issue in express.

@dougwilson dougwilson self-assigned this Jan 2, 2016
@dougwilson dougwilson added the 4.x label Jan 2, 2016
@brandonburkett
Copy link

I did some more digging and oddly, it only seems to do it for me when I run with --debug node flag.

This command does not exit:

PORT=3000 NODE_ENV=development NODE_PATH=. FORCE_COLOR=1 node server.js --color

While this one will exit after a res.status(500).send('whatever')

PORT=3000 NODE_ENV=development NODE_PATH=. FORCE_COLOR=1 node --debug server.js --color

Here's my middleware:

   app.use(function (err, req, res, next) {
        // If the error object doesn't exists
        if (!err) {
            return next();
        }

        // Log it
        logger.error(err);
        if (err.stack) {
            logger.error(err.stack);
        }

        // Error page
        return res.status(err.status || 500).send((['development'].indexOf(process.env.NODE_ENV) !== -1) ? err : {message: 'something went wrong'});
    });

And here is a test API that crashes for me:

    app.route('/api/test').get(function(req, res, next) {
        return next({'message':'test error'});
    });

And here is my terminal output:

error:  
{ message: 'test error' }
Segmentation fault: 11

I am using express 4.13.3 and node 5.3.0. I'll test with node 5.2.x to see if it does the same thing.

@dougwilson
Copy link
Contributor

Ah, a "Segmentation fault: 11". This is a Node.js bug, not an express bug. The way node.js works is that there is no way to cause this, so encountering one means there is something very wrong going on in the node.js core code. Can you open an issue against node.js, link here, and help them with reproducing?

@dougwilson
Copy link
Contributor

Looks like it has already been reported: nodejs/node#4382

@brandonburkett
Copy link

Awesome! Thanks for the help on this.

@dougwilson
Copy link
Contributor

No problem! Sounds like it should be addressed in 5.3.1 or 5.4.0, which ever comes first.

@calidion
Copy link
Author

calidion commented Jan 3, 2016

@dougwilson I am using v4.2.3.
and it doesn't have stack trace when exit.

@calidion
Copy link
Author

calidion commented Jan 3, 2016

and debug is not enabled for me.

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

No branches or pull requests

3 participants