File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
test/integration/gh-issues Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,14 @@ class Query extends EventEmitter {
135135 return this . handleError ( this . _canceledDueToError , con )
136136 }
137137 if ( this . callback ) {
138- this . callback ( null , this . _results )
138+ try {
139+ this . callback ( null , this . _results )
140+ }
141+ catch ( err ) {
142+ process . nextTick ( ( ) => {
143+ throw err
144+ } )
145+ }
139146 }
140147 this . emit ( 'end' , this . _results )
141148 }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+ var helper = require ( './../test-helper' )
3+ var assert = require ( 'assert' )
4+
5+ var callbackError = new Error ( 'TEST: Throw in callback' )
6+
7+ const suite = new helper . Suite ( )
8+
9+ suite . test ( 'it should cleanup client even if an error is thrown in a callback' , ( done ) => {
10+ // temporarily replace the test framework's uncaughtException handlers
11+ // with a custom one that ignores the callbackError
12+ let original_handlers = process . listeners ( 'uncaughtException' )
13+ process . removeAllListeners ( 'uncaughtException' )
14+ process . on ( 'uncaughtException' , ( err ) => {
15+ if ( err != callbackError ) {
16+ original_handlers [ 0 ] ( err )
17+ }
18+ } )
19+
20+ // throw an error in a callback and verify that a subsequent query works without error
21+ var client = helper . client ( )
22+ client . query ( 'SELECT NOW()' , ( err ) => {
23+ assert ( ! err )
24+ setTimeout ( reuseClient , 50 )
25+ throw callbackError
26+ } )
27+
28+ function reuseClient ( ) {
29+ client . query ( 'SELECT NOW()' , ( err ) => {
30+ assert ( ! err )
31+
32+ // restore the test framework's uncaughtException handlers
33+ for ( let handler of original_handlers ) {
34+ process . on ( 'uncaughtException' , handler )
35+ }
36+
37+ client . end ( done )
38+ } )
39+ }
40+ } )
You can’t perform that action at this time.
0 commit comments