Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…2753) * Fix #2556 (handleRowDescription of null) by keeping callback errors from interfering with cleanup * Added regression test for #2556
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
var helper = require('./../test-helper') | ||
var assert = require('assert') | ||
|
||
var callbackError = new Error('TEST: Throw in callback') | ||
|
||
const suite = new helper.Suite() | ||
|
||
suite.test('it should cleanup client even if an error is thrown in a callback', (done) => { | ||
// temporarily replace the test framework's uncaughtException handlers | ||
// with a custom one that ignores the callbackError | ||
let original_handlers = process.listeners('uncaughtException') | ||
process.removeAllListeners('uncaughtException') | ||
process.on('uncaughtException', (err) => { | ||
if (err != callbackError) { | ||
original_handlers[0](err) | ||
} | ||
}) | ||
|
||
// throw an error in a callback and verify that a subsequent query works without error | ||
var client = helper.client() | ||
client.query('SELECT NOW()', (err) => { | ||
assert(!err) | ||
setTimeout(reuseClient, 50) | ||
throw callbackError | ||
}) | ||
|
||
function reuseClient() { | ||
client.query('SELECT NOW()', (err) => { | ||
assert(!err) | ||
|
||
// restore the test framework's uncaughtException handlers | ||
for (let handler of original_handlers) { | ||
process.on('uncaughtException', handler) | ||
} | ||
|
||
client.end(done) | ||
}) | ||
} | ||
}) |