mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Unresponsiveness after throwing an exception in callback

Open aarong opened this issue 15 years ago • 1 comments

When an exception is thrown in the query() callback, subsequent calls to query() receive no callback. In the code below only one callback will be reported. If you add the try/catch lines back in and all queries receive callbacks.

(I do not intentionally throw exceptions from the callback, but I had some bad code in the callback and it was a huge pain figuring out why my queries would start hanging out of nowhere.)

// Never gets triggered
dbClient.on('error', function (inError) {
    console.log('db error'); 
});

// Keep going after exceptions
process.on('uncaughtException', function () {});

// Perform the same query a bunch of times
setInterval(function () {
    console.log('Trying query');
    dbClient.query(
        "SELECT 1",
        function (inError, inResult) {

            console.log('Received query callback');

            // try {
                (function () { throw 'lul'; })();
            // } catch (e) {}

        }
    );
    }, 1000
);

aarong avatar Aug 16 '11 17:08 aarong

This is not a bug. Please have a look at: http://debuggable.com/posts/node-js-dealing-with-uncaught-exceptions:4c933d54-1428-443c-928d-4e1ecbdd56cb

If you have an uncaught exception, log the event and then kill the process. Everything else is madness.

felixge avatar Aug 17 '11 11:08 felixge