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

Process terminates before HTTP request originating from uncaughtException handler fires #113

Closed
benvinegar opened this issue Jan 27, 2016 · 2 comments

Comments

@benvinegar
Copy link

Consider the following script (test.js):

var http = require('http');

process.on('uncaughtException', function () {
    var options = {
        hostname: 'httpbin.org',
        path: '/get',
        method: 'GET',
        port: '80'
    };

    console.log('Initiating request to: http://httpbin.org/get');
    var req = http.request(options, function(res) {
        console.log('Request finished:');
        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            console.log(chunk);
        });
    });
    req.on('error', function(e) {
        console.log('request errored:', e);
    });
    req.end();
});

foo(); // undefined / throws exception

When run via node:

➜  node test.js
Initiating request to: http://httpbin.org/get
Request finished:
{
  "args": {},
  "headers": {
    "Host": "httpbin.org"
  },
  "origin": "73.162.26.213",
  "url": "http://httpbin.org/get"
}

When run via node-dev:

➜  node-dev test.js
ReferenceError: foo is not defined
    at Object.<anonymous> (/Users/me/Projects/express-example/test.js:30:1)
    at Module._compile (module.js:434:26)
    at Module._extensions..js (module.js:452:10)
    at Object.nodeDevHook [as .js] (/Users/me/.nvm/versions/node/v4.0.0/lib/node_modules/node-dev/lib/hook.js:43:7)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/me/.nvm/versions/node/v4.0.0/lib/node_modules/node-dev/lib/wrap.js:58:1)
    at Module._compile (module.js:434:26)
Initiating request to: http://httpbin.org/get
[ERROR] 17:13:03 ReferenceError
# process is terminated; request is never actually fired (doesn't reach server)

This is resulting in getsentry/raven-node#143

@benvinegar benvinegar changed the title Process terminates before HTTP request originating from uncaughtException handler fire Process terminates before HTTP request originating from uncaughtException handler fires Jan 27, 2016
@fgnass
Copy link
Owner

fgnass commented Jan 27, 2016

Thanks for this elaborate bug report! I'll use my slack time on Friday to come up with a fix.

fgnass added a commit that referenced this issue Jan 29, 2016
node-dev now checks if a custom uncaughtException handler is present
and if so, does not terminate the child process but expects the custom
handler to do so.
@fgnass
Copy link
Owner

fgnass commented Jan 29, 2016

In v3.0.0 node-dev now checks if there is another uncaughtException handler registered. If so, it does not terminate the process but expects the custom handler to do it.

This is in line with what the raven docs suggest:

client.patchGlobal(function() {
    console.log('Bye, bye, world.');
    process.exit(1);
});

@fgnass fgnass closed this as completed Jan 29, 2016
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

2 participants