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 @@ -97,7 +97,9 @@ function Connection(options = {}) {
97
97
}
98
98
99
99
function destroy ( ) {
100
- error ( errors . connection ( 'DESTROYED' , options ) )
100
+ const err = errors . connection ( 'DESTROYED' , options )
101
+ backend . query && backend . query . reject ( err )
102
+ error ( err )
101
103
socket . destroy ( )
102
104
}
103
105
Original file line number Diff line number Diff line change @@ -354,13 +354,10 @@ function Postgres(a, b) {
354
354
355
355
let destroy
356
356
357
- if ( timeout === 0 )
358
- return ended = Promise . all ( all . map ( c => c . destroy ( ) ) ) . then ( ( ) => undefined )
359
-
360
357
return ended = Promise . race ( [
361
358
Promise . resolve ( arrayTypesPromise ) . then ( ( ) => Promise . all ( all . map ( c => c . end ( ) ) ) )
362
359
] . concat (
363
- timeout > 0
360
+ timeout === 0 || timeout > 0
364
361
? new Promise ( r => destroy = setTimeout ( ( ) => ( all . map ( c => c . destroy ( ) ) , r ( ) ) , timeout * 1000 ) )
365
362
: [ ]
366
363
) )
Original file line number Diff line number Diff line change @@ -425,6 +425,13 @@ t('Connection destroyed', async() => {
425
425
return [ 'CONNECTION_DESTROYED' , await sql `` . catch ( x => x . code ) ]
426
426
} )
427
427
428
+ t ( 'Connection destroyed with query before' , async ( ) => {
429
+ const sql = postgres ( options )
430
+ let error = sql `select pg_sleep(0.2)` . catch ( err => err . code )
431
+ sql . end ( { timeout : 0 } )
432
+ return [ 'CONNECTION_DESTROYED' , await error ]
433
+ } )
434
+
428
435
t ( 'Message not supported' , async ( ) => {
429
436
await sql `create table test (x int)`
430
437
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