File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -143,12 +143,22 @@ Client.prototype.connect = function(callback) {
143
143
} ) ;
144
144
145
145
con . on ( 'readyForQuery' , function ( ) {
146
+ var error ;
146
147
if ( self . activeQuery ) {
147
- self . activeQuery . handleReadyForQuery ( ) ;
148
+ //try/catch/rethrow to ensure exceptions don't prevent the queryQueue from
149
+ //being processed
150
+ try {
151
+ self . activeQuery . handleReadyForQuery ( ) ;
152
+ } catch ( e ) {
153
+ error = e ;
154
+ }
148
155
}
149
156
self . activeQuery = null ;
150
157
self . readyForQuery = true ;
151
158
self . _pulseQueryQueue ( ) ;
159
+ if ( error ) {
160
+ throw error ;
161
+ }
152
162
} ) ;
153
163
154
164
con . on ( 'error' , function ( error ) {
Original file line number Diff line number Diff line change @@ -208,15 +208,23 @@ var clientBuilder = function(config) {
208
208
} ) ;
209
209
210
210
connection . on ( '_readyForQuery' , function ( ) {
211
+ var error ;
211
212
var q = this . _activeQuery ;
212
213
//a named query finished being prepared
213
214
if ( this . _namedQuery ) {
214
215
this . _namedQuery = false ;
215
216
this . _sendQueryPrepared ( q . name , q . values || [ ] ) ;
216
217
} else {
217
- connection . _activeQuery . handleReadyForQuery ( connection . _lastMeta ) ;
218
+ //try/catch/rethrow to ensure exceptions don't prevent the queryQueue from
219
+ //being processed
220
+ try {
221
+ connection . _activeQuery . handleReadyForQuery ( connection . _lastMeta ) ;
222
+ } catch ( e ) {
223
+ error = e ;
224
+ }
218
225
connection . _activeQuery = null ;
219
226
connection . _pulseQueryQueue ( ) ;
227
+ if ( error ) throw error ;
220
228
}
221
229
} ) ;
222
230
connection . on ( 'copyInResponse' , function ( ) {
Original file line number Diff line number Diff line change
1
+ var helper = require ( __dirname + '/test-helper' ) ;
2
+ var util = require ( 'util' ) ;
3
+
4
+ test ( 'error during query execution' , function ( ) {
5
+ var client = new Client ( helper . args ) ;
6
+ process . removeAllListeners ( 'uncaughtException' ) ;
7
+ assert . emits ( process , 'uncaughtException' , function ( ) {
8
+ assert . equal ( client . activeQuery , null , 'should remove active query even if error happens in callback' ) ;
9
+ client . query ( 'SELECT * FROM blah' , assert . success ( function ( result ) {
10
+ assert . equal ( result . rows . length , 1 ) ;
11
+ client . end ( ) ;
12
+ } ) ) ;
13
+ } ) ;
14
+ client . connect ( assert . success ( function ( ) {
15
+ client . query ( 'CREATE TEMP TABLE "blah"(data text)' , assert . success ( function ( ) {
16
+ var q = client . query ( 'INSERT INTO blah(data) VALUES($1)' , [ 'yo' ] , assert . success ( function ( ) {
17
+ assert . emits ( client , 'drain' ) ;
18
+ throw new Error ( 'WHOOOAAAHH!!' ) ;
19
+ } ) ) ;
20
+ } ) ) ;
21
+ } ) ) ;
22
+ } ) ;
You can’t perform that action at this time.
0 commit comments