4444let
4545// Signature bytes for each message type
4646INIT = 0x01 , // 0000 0001 // INIT <user_agent>
47- ACK_FAILURE = 0x0E , // 0000 1110 // ACK_FAILURE
47+ ACK_FAILURE = 0x0E , // 0000 1110 // ACK_FAILURE - unused
4848RESET = 0x0F , // 0000 1111 // RESET
4949RUN = 0x10 , // 0001 0000 // RUN <statement> <parameters>
5050DISCARD_ALL = 0x2F , // 0010 1111 // DISCARD *
@@ -106,7 +106,6 @@ class Connection {
106106 this . _packer = packStreamUtil . createLatestPacker ( this . _chunker ) ;
107107 this . _unpacker = packStreamUtil . createLatestUnpacker ( disableLosslessIntegers ) ;
108108
109- this . _ackFailureMuted = false ;
110109 this . _currentFailure = null ;
111110
112111 this . _state = new ConnectionState ( this ) ;
@@ -247,7 +246,7 @@ class Connection {
247246 } finally {
248247 this . _updateCurrentObserver ( ) ;
249248 // Things are now broken. Pending observers will get FAILURE messages routed until we are done handling this failure.
250- this . _ackFailureIfNeeded ( ) ;
249+ this . _resetOnFailure ( ) ;
251250 }
252251 break ;
253252 case IGNORED :
@@ -279,7 +278,7 @@ class Connection {
279278 this . _packer . packStruct ( INIT , [ this . _packable ( clientName ) , this . _packable ( token ) ] ,
280279 ( err ) => this . _handleFatalError ( err ) ) ;
281280 this . _chunker . messageBoundary ( ) ;
282- this . sync ( ) ;
281+ this . flush ( ) ;
283282 }
284283 }
285284
@@ -322,17 +321,12 @@ class Connection {
322321
323322 /**
324323 * 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.
326325 * @return {Promise<void> } promise resolved when SUCCESS-message response arrives, or failed when other response messages arrives.
327326 */
328327 resetAndFlush ( ) {
329- if ( this . _log . isDebugEnabled ( ) ) {
330- this . _log . debug ( `${ this } C: RESET` ) ;
331- }
332- this . _ackFailureMuted = true ;
333-
334328 return new Promise ( ( resolve , reject ) => {
335- const observer = {
329+ this . _reset ( {
336330 onNext : record => {
337331 const neo4jError = this . _handleProtocolError ( 'Received RECORD as a response for RESET: ' + JSON . stringify ( record ) ) ;
338332 reject ( neo4jError ) ;
@@ -347,50 +341,37 @@ class Connection {
347341 }
348342 } ,
349343 onCompleted : ( ) => {
350- this . _ackFailureMuted = false ;
351344 resolve ( ) ;
352345 }
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+ } ) ;
360347 } ) ;
361348 }
362349
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 ( {
373352 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 ) ) ;
375354 } ,
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 ;
383358 } ,
384359 onCompleted : ( ) => {
385360 this . _currentFailure = null ;
386361 }
387- } ;
362+ } ) ;
363+ }
364+
365+ _reset ( observer ) {
366+ if ( this . _log . isDebugEnabled ( ) ) {
367+ this . _log . debug ( `${ this } C: RESET` ) ;
368+ }
388369
389370 const queued = this . _queueObserver ( observer ) ;
390371 if ( queued ) {
391- this . _packer . packStruct ( ACK_FAILURE , [ ] , err => this . _handleFatalError ( err ) ) ;
372+ this . _packer . packStruct ( RESET , [ ] , err => this . _handleFatalError ( err ) ) ;
392373 this . _chunker . messageBoundary ( ) ;
393- this . sync ( ) ;
374+ this . flush ( ) ;
394375 }
395376 }
396377
@@ -431,10 +412,9 @@ class Connection {
431412 }
432413
433414 /**
434- * Synchronize - flush all queued outgoing messages and route their responses
435- * to their respective handlers.
415+ * Flush all queued outgoing messages.
436416 */
437- sync ( ) {
417+ flush ( ) {
438418 this . _chunker . flush ( ) ;
439419 }
440420
@@ -477,7 +457,6 @@ class Connection {
477457 }
478458
479459 _handleProtocolError ( message ) {
480- this . _ackFailureMuted = false ;
481460 this . _currentFailure = null ;
482461 this . _updateCurrentObserver ( ) ;
483462 const error = newError ( message , PROTOCOL_ERROR ) ;
0 commit comments