File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " tinypg" ,
3
- "version" : " 2.0.0-alpha.13 " ,
3
+ "version" : " 2.0.0-alpha.14 " ,
4
4
"description" : " Easy way to call sql files using postgres." ,
5
5
"main" : " dist/index.js" ,
6
6
"typings" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -189,7 +189,27 @@ export class TinyPg {
189
189
190
190
this . events . emit ( 'query' , query_context )
191
191
192
+ let call_completed = false
193
+
194
+ // Work around node-postgres swallowing queries after a connection error
195
+ // https://github.com/brianc/node-postgres/issues/718
196
+ const connection_failed_promise = new Promise < T . Result < T > > ( ( resolve , reject ) => {
197
+ const checkForConnection = ( ) => {
198
+ if ( call_completed ) {
199
+ resolve ( )
200
+ } else if ( client [ 'connection' ] . stream . destroyed ) {
201
+ reject ( new Error ( 'Connection terminated' ) )
202
+ } else {
203
+ setTimeout ( checkForConnection , 500 )
204
+ }
205
+ }
206
+
207
+ setTimeout ( checkForConnection , 500 )
208
+ } )
209
+
192
210
const callComplete = _ . once ( ( error : Error , data : T . Result < T > ) => {
211
+ call_completed = true
212
+
193
213
if ( error && ( ! error [ 'code' ] || _ . startsWith ( error [ 'code' ] , '57P' ) ) ) {
194
214
( < any > client ) . release ( error )
195
215
} else {
@@ -235,7 +255,7 @@ export class TinyPg {
235
255
} )
236
256
} )
237
257
238
- return query_promise
258
+ return Promise . race ( [ connection_failed_promise , query_promise ] )
239
259
. then ( result => {
240
260
callComplete ( null , result )
241
261
return result
You can’t perform that action at this time.
0 commit comments