File tree 3 files changed +11
-5
lines changed
3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,9 @@ function Connection(options = {}) {
79
79
}
80
80
81
81
function destroy ( ) {
82
- error ( errors . connection ( 'DESTROYED' , options ) )
82
+ const err = errors . connection ( 'DESTROYED' , options )
83
+ backend . query && backend . query . reject ( err )
84
+ error ( err )
83
85
socket . destroy ( )
84
86
}
85
87
Original file line number Diff line number Diff line change @@ -322,13 +322,10 @@ function Postgres(a, b) {
322
322
323
323
let destroy
324
324
325
- if ( timeout === 0 )
326
- return ended = Promise . all ( all . map ( c => c . destroy ( ) ) ) . then ( ( ) => undefined )
327
-
328
325
return ended = Promise . race ( [
329
326
Promise . all ( all . map ( c => c . end ( ) ) )
330
327
] . concat (
331
- timeout > 0
328
+ timeout === 0 || timeout > 0
332
329
? new Promise ( r => destroy = setTimeout ( ( ) => ( all . map ( c => c . destroy ( ) ) , r ( ) ) , timeout * 1000 ) )
333
330
: [ ]
334
331
) )
Original file line number Diff line number Diff line change @@ -419,6 +419,13 @@ t('Connection destroyed', async() => {
419
419
return [ 'CONNECTION_DESTROYED' , await sql `` . catch ( x => x . code ) ]
420
420
} )
421
421
422
+ t ( 'Connection destroyed with query before' , async ( ) => {
423
+ const sql = postgres ( options )
424
+ let error = sql `select pg_sleep(0.2)` . catch ( err => err . code )
425
+ sql . end ( { timeout : 0 } )
426
+ return [ 'CONNECTION_DESTROYED' , await error ]
427
+ } )
428
+
422
429
t ( 'Message not supported' , async ( ) => {
423
430
await sql `create table test (x int)`
424
431
return [ 'MESSAGE_NOT_SUPPORTED' , await sql `copy test to stdout` . catch ( x => x . code ) ]
You can’t perform that action at this time.
0 commit comments