@@ -141,10 +141,10 @@ class Client extends EventEmitter {
141
141
if ( this . _connectionCallback ) {
142
142
this . _connectionCallback ( error )
143
143
} else {
144
- this . handleErrorWhileConnected ( error )
144
+ this . _handleErrorEvent ( error )
145
145
}
146
146
} else if ( ! this . _connectionError ) {
147
- this . handleErrorWhileConnected ( error )
147
+ this . _handleErrorEvent ( error )
148
148
}
149
149
}
150
150
@@ -173,27 +173,27 @@ class Client extends EventEmitter {
173
173
174
174
_attachListeners ( con ) {
175
175
// password request handling
176
- con . on ( 'authenticationCleartextPassword' , this . handleAuthenticationCleartextPassword . bind ( this ) )
176
+ con . on ( 'authenticationCleartextPassword' , this . _handleAuthCleartextPassword . bind ( this ) )
177
177
// password request handling
178
- con . on ( 'authenticationMD5Password' , this . handleAuthenticationMD5Password . bind ( this ) )
178
+ con . on ( 'authenticationMD5Password' , this . _handleAuthMD5Password . bind ( this ) )
179
179
// password request handling (SASL)
180
- con . on ( 'authenticationSASL' , this . handleAuthenticationSASL . bind ( this ) )
181
- con . on ( 'authenticationSASLContinue' , this . handleAuthenticationSASLContinue . bind ( this ) )
182
- con . on ( 'authenticationSASLFinal' , this . handleAuthenticationSASLFinal . bind ( this ) )
183
- con . on ( 'backendKeyData' , this . handleBackendKeyData . bind ( this ) )
184
- con . on ( 'error' , this . handleErrorWhileConnecting )
185
- con . on ( 'errorMessage' , this . handleErrorMessage )
186
- con . on ( 'readyForQuery' , this . handleReadyForQuery . bind ( this ) )
187
- con . on ( 'notice' , this . handleNotice . bind ( this ) )
188
- con . on ( 'rowDescription' , this . handleRowDescription . bind ( this ) )
189
- con . on ( 'dataRow' , this . handleDataRow . bind ( this ) )
190
- con . on ( 'portalSuspended' , this . handlePortalSuspended . bind ( this ) )
191
- con . on ( 'emptyQuery' , this . handleEmptyQuery . bind ( this ) )
192
- con . on ( 'commandComplete' , this . handleCommandComplete . bind ( this ) )
193
- con . on ( 'parseComplete' , this . handleParseComplete . bind ( this ) )
194
- con . on ( 'copyInResponse' , this . handleCopyInResponse . bind ( this ) )
195
- con . on ( 'copyData' , this . handleCopyData . bind ( this ) )
196
- con . on ( 'notification' , this . handleNotification . bind ( this ) )
180
+ con . on ( 'authenticationSASL' , this . _handleAuthSASL . bind ( this ) )
181
+ con . on ( 'authenticationSASLContinue' , this . _handleAuthSASLContinue . bind ( this ) )
182
+ con . on ( 'authenticationSASLFinal' , this . _handleAuthSASLFinal . bind ( this ) )
183
+ con . on ( 'backendKeyData' , this . _handleBackendKeyData . bind ( this ) )
184
+ con . on ( 'error' , this . _handleErrorEvent )
185
+ con . on ( 'errorMessage' , this . _handleErrorMessage )
186
+ con . on ( 'readyForQuery' , this . _handleReadyForQuery . bind ( this ) )
187
+ con . on ( 'notice' , this . _handleNotice . bind ( this ) )
188
+ con . on ( 'rowDescription' , this . _handleRowDescription . bind ( this ) )
189
+ con . on ( 'dataRow' , this . _handleDataRow . bind ( this ) )
190
+ con . on ( 'portalSuspended' , this . _handlePortalSuspended . bind ( this ) )
191
+ con . on ( 'emptyQuery' , this . _handleEmptyQuery . bind ( this ) )
192
+ con . on ( 'commandComplete' , this . _handleCommandComplete . bind ( this ) )
193
+ con . on ( 'parseComplete' , this . _handleParseComplete . bind ( this ) )
194
+ con . on ( 'copyInResponse' , this . _handleCopyInResponse . bind ( this ) )
195
+ con . on ( 'copyData' , this . _handleCopyData . bind ( this ) )
196
+ con . on ( 'notification' , this . _handleNotification . bind ( this ) )
197
197
}
198
198
199
199
// TODO(bmc): deprecate pgpass "built in" integration since this.password can be a function
@@ -232,50 +232,47 @@ class Client extends EventEmitter {
232
232
}
233
233
}
234
234
235
- handleAuthenticationCleartextPassword ( msg ) {
235
+ _handleAuthCleartextPassword ( msg ) {
236
236
this . _checkPgPass ( ( ) => {
237
237
this . connection . password ( this . password )
238
238
} )
239
239
}
240
240
241
- handleAuthenticationMD5Password ( msg ) {
241
+ _handleAuthMD5Password ( msg ) {
242
242
this . _checkPgPass ( ( msg ) => {
243
243
const hashedPassword = utils . postgresMd5PasswordHash ( this . user , this . password , msg . salt )
244
244
this . connection . password ( hashedPassword )
245
245
} )
246
246
}
247
247
248
- handleAuthenticationSASL ( msg ) {
248
+ _handleAuthSASL ( msg ) {
249
249
this . _checkPgPass ( ( msg ) => {
250
250
this . saslSession = sasl . startSession ( msg . mechanisms )
251
251
const con = this . connection
252
252
con . sendSASLInitialResponseMessage ( saslSession . mechanism , saslSession . response )
253
253
} )
254
254
}
255
255
256
- handleAuthenticationSASLContinue ( msg ) {
256
+ _handleAuthSASLContinue ( msg ) {
257
257
const { saslSession } = this
258
258
sasl . continueSession ( saslSession , this . password , msg . data )
259
259
con . sendSCRAMClientFinalMessage ( saslSession . response )
260
260
}
261
261
262
- handleAuthenticationSASLFinal ( msg ) {
262
+ _handleAuthSASLFinal ( msg ) {
263
263
sasl . finalizeSession ( this . saslSession , msg . data )
264
264
this . saslSession = null
265
265
}
266
266
267
- handleBackendKeyData ( msg ) {
267
+ _handleBackendKeyData ( msg ) {
268
268
this . processID = msg . processID
269
269
this . secretKey = msg . secretKey
270
270
}
271
271
272
- handleReadyForQuery ( msg ) {
272
+ _handleReadyForQuery ( msg ) {
273
273
if ( this . _connecting ) {
274
274
this . _connecting = false
275
275
this . _connected = true
276
- const con = this . connection
277
- con . removeListener ( 'error' , this . handleErrorWhileConnecting )
278
- con . on ( 'error' , this . handleErrorWhileConnected )
279
276
clearTimeout ( this . connectionTimeoutHandle )
280
277
281
278
// process possible callback argument to Client#connect
@@ -296,8 +293,9 @@ class Client extends EventEmitter {
296
293
this . _pulseQueryQueue ( )
297
294
}
298
295
299
- // if we receieve an error event or error message during the connection process we handle it here
300
- handleErrorWhileConnecting = ( err ) => {
296
+ // if we receieve an error event or error message
297
+ // during the connection process we handle it here
298
+ _handleErrorWhileConnecting = ( err ) => {
301
299
if ( this . _connectionError ) {
302
300
// TODO(bmc): this is swallowing errors - we shouldn't do this
303
301
return
@@ -313,54 +311,57 @@ class Client extends EventEmitter {
313
311
// if we're connected and we receive an error event from the connection
314
312
// this means the socket is dead - do a hard abort of all queries and emit
315
313
// the socket error on the client as well
316
- handleErrorWhileConnected = ( err ) => {
314
+ _handleErrorEvent = ( err ) => {
315
+ if ( this . _connecting ) {
316
+ return this . _handleErrorWhileConnecting ( err )
317
+ }
317
318
this . _queryable = false
318
319
this . _errorAllQueries ( err )
319
320
this . emit ( 'error' , err )
320
321
}
321
322
322
323
// handle error messages from the postgres backend
323
- handleErrorMessage = ( msg ) => {
324
+ _handleErrorMessage = ( msg ) => {
324
325
if ( this . _connecting ) {
325
- return this . handleErrorWhileConnecting ( msg )
326
+ return this . _handleErrorWhileConnecting ( msg )
326
327
}
327
328
const activeQuery = this . activeQuery
328
329
329
330
if ( ! activeQuery ) {
330
- this . handleErrorWhileConnected ( msg )
331
+ this . _handleErrorEvent ( msg )
331
332
return
332
333
}
333
334
334
335
this . activeQuery = null
335
336
activeQuery . handleError ( msg , this . connection )
336
337
}
337
338
338
- handleRowDescription ( msg ) {
339
+ _handleRowDescription ( msg ) {
339
340
// delegate rowDescription to active query
340
341
this . activeQuery . handleRowDescription ( msg )
341
342
}
342
343
343
- handleDataRow ( msg ) {
344
+ _handleDataRow ( msg ) {
344
345
// delegate dataRow to active query
345
346
this . activeQuery . handleDataRow ( msg )
346
347
}
347
348
348
- handlePortalSuspended ( msg ) {
349
+ _handlePortalSuspended ( msg ) {
349
350
// delegate portalSuspended to active query
350
351
this . activeQuery . handlePortalSuspended ( this . connection )
351
352
}
352
353
353
- handleEmptyQuery ( msg ) {
354
+ _handleEmptyQuery ( msg ) {
354
355
// delegate emptyQuery to active query
355
356
this . activeQuery . handleEmptyQuery ( this . connection )
356
357
}
357
358
358
- handleCommandComplete ( msg ) {
359
+ _handleCommandComplete ( msg ) {
359
360
// delegate commandComplete to active query
360
361
this . activeQuery . handleCommandComplete ( msg , this . connection )
361
362
}
362
363
363
- handleParseComplete ( msg ) {
364
+ _handleParseComplete ( msg ) {
364
365
// if a prepared statement has a name and properly parses
365
366
// we track that its already been executed so we don't parse
366
367
// it again on the same client
@@ -369,19 +370,19 @@ class Client extends EventEmitter {
369
370
}
370
371
}
371
372
372
- handleCopyInResponse ( msg ) {
373
+ _handleCopyInResponse ( msg ) {
373
374
this . activeQuery . handleCopyInResponse ( this . connection )
374
375
}
375
376
376
- handleCopyData ( msg ) {
377
+ _handleCopyData ( msg ) {
377
378
this . activeQuery . handleCopyData ( msg , this . connection )
378
379
}
379
380
380
- handleNotification ( msg ) {
381
+ _handleNotification ( msg ) {
381
382
this . emit ( 'notification' , msg )
382
383
}
383
384
384
- handleNotice ( msg ) {
385
+ _handleNotice ( msg ) {
385
386
this . emit ( 'notice' , msg )
386
387
}
387
388
0 commit comments