44
44
let
45
45
// Signature bytes for each message type
46
46
INIT = 0x01 , // 0000 0001 // INIT <user_agent>
47
- ACK_FAILURE = 0x0E , // 0000 1110 // ACK_FAILURE
47
+ ACK_FAILURE = 0x0E , // 0000 1110 // ACK_FAILURE - unused
48
48
RESET = 0x0F , // 0000 1111 // RESET
49
49
RUN = 0x10 , // 0001 0000 // RUN <statement> <parameters>
50
50
DISCARD_ALL = 0x2F , // 0010 1111 // DISCARD *
@@ -106,7 +106,6 @@ class Connection {
106
106
this . _packer = packStreamUtil . createLatestPacker ( this . _chunker ) ;
107
107
this . _unpacker = packStreamUtil . createLatestUnpacker ( disableLosslessIntegers ) ;
108
108
109
- this . _ackFailureMuted = false ;
110
109
this . _currentFailure = null ;
111
110
112
111
this . _state = new ConnectionState ( this ) ;
@@ -247,7 +246,7 @@ class Connection {
247
246
} finally {
248
247
this . _updateCurrentObserver ( ) ;
249
248
// Things are now broken. Pending observers will get FAILURE messages routed until we are done handling this failure.
250
- this . _ackFailureIfNeeded ( ) ;
249
+ this . _resetOnFailure ( ) ;
251
250
}
252
251
break ;
253
252
case IGNORED :
@@ -279,7 +278,7 @@ class Connection {
279
278
this . _packer . packStruct ( INIT , [ this . _packable ( clientName ) , this . _packable ( token ) ] ,
280
279
( err ) => this . _handleFatalError ( err ) ) ;
281
280
this . _chunker . messageBoundary ( ) ;
282
- this . sync ( ) ;
281
+ this . flush ( ) ;
283
282
}
284
283
}
285
284
@@ -322,17 +321,12 @@ class Connection {
322
321
323
322
/**
324
323
* Send a RESET-message to the database. Mutes failure handling.
325
- * Message is immediately flushed to the network. Separate {@link Connection#sync ()} call is not required.
324
+ * Message is immediately flushed to the network. Separate {@link Connection#flush ()} call is not required.
326
325
* @return {Promise<void> } promise resolved when SUCCESS-message response arrives, or failed when other response messages arrives.
327
326
*/
328
327
resetAndFlush ( ) {
329
- if ( this . _log . isDebugEnabled ( ) ) {
330
- this . _log . debug ( `${ this } C: RESET` ) ;
331
- }
332
- this . _ackFailureMuted = true ;
333
-
334
328
return new Promise ( ( resolve , reject ) => {
335
- const observer = {
329
+ this . _reset ( {
336
330
onNext : record => {
337
331
const neo4jError = this . _handleProtocolError ( 'Received RECORD as a response for RESET: ' + JSON . stringify ( record ) ) ;
338
332
reject ( neo4jError ) ;
@@ -347,50 +341,37 @@ class Connection {
347
341
}
348
342
} ,
349
343
onCompleted : ( ) => {
350
- this . _ackFailureMuted = false ;
351
344
resolve ( ) ;
352
345
}
353
- } ;
354
- const queued = this . _queueObserver ( observer ) ;
355
- if ( queued ) {
356
- this . _packer . packStruct ( RESET , [ ] , err => this . _handleFatalError ( err ) ) ;
357
- this . _chunker . messageBoundary ( ) ;
358
- this . sync ( ) ;
359
- }
346
+ } ) ;
360
347
} ) ;
361
348
}
362
349
363
- _ackFailureIfNeeded ( ) {
364
- if ( this . _ackFailureMuted ) {
365
- return ;
366
- }
367
-
368
- if ( this . _log . isDebugEnabled ( ) ) {
369
- this . _log . debug ( `${ this } C: ACK_FAILURE` ) ;
370
- }
371
-
372
- const observer = {
350
+ _resetOnFailure ( ) {
351
+ this . _reset ( {
373
352
onNext : record => {
374
- this . _handleProtocolError ( 'Received RECORD as a response for ACK_FAILURE : ' + JSON . stringify ( record ) ) ;
353
+ this . _handleProtocolError ( 'Received RECORD as a response for RESET : ' + JSON . stringify ( record ) ) ;
375
354
} ,
376
- onError : error => {
377
- if ( ! this . _isBroken && ! this . _ackFailureMuted ) {
378
- // not handling a fatal error and RESET did not cause the given error - looks like a protocol violation
379
- this . _handleProtocolError ( 'Received FAILURE as a response for ACK_FAILURE: ' + error ) ;
380
- } else {
381
- this . _currentFailure = null ;
382
- }
355
+ // clear the current failure when response for RESET is received
356
+ onError : ( ) => {
357
+ this . _currentFailure = null ;
383
358
} ,
384
359
onCompleted : ( ) => {
385
360
this . _currentFailure = null ;
386
361
}
387
- } ;
362
+ } ) ;
363
+ }
364
+
365
+ _reset ( observer ) {
366
+ if ( this . _log . isDebugEnabled ( ) ) {
367
+ this . _log . debug ( `${ this } C: RESET` ) ;
368
+ }
388
369
389
370
const queued = this . _queueObserver ( observer ) ;
390
371
if ( queued ) {
391
- this . _packer . packStruct ( ACK_FAILURE , [ ] , err => this . _handleFatalError ( err ) ) ;
372
+ this . _packer . packStruct ( RESET , [ ] , err => this . _handleFatalError ( err ) ) ;
392
373
this . _chunker . messageBoundary ( ) ;
393
- this . sync ( ) ;
374
+ this . flush ( ) ;
394
375
}
395
376
}
396
377
@@ -431,10 +412,9 @@ class Connection {
431
412
}
432
413
433
414
/**
434
- * Synchronize - flush all queued outgoing messages and route their responses
435
- * to their respective handlers.
415
+ * Flush all queued outgoing messages.
436
416
*/
437
- sync ( ) {
417
+ flush ( ) {
438
418
this . _chunker . flush ( ) ;
439
419
}
440
420
@@ -477,7 +457,6 @@ class Connection {
477
457
}
478
458
479
459
_handleProtocolError ( message ) {
480
- this . _ackFailureMuted = false ;
481
460
this . _currentFailure = null ;
482
461
this . _updateCurrentObserver ( ) ;
483
462
const error = newError ( message , PROTOCOL_ERROR ) ;
0 commit comments