File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -387,9 +387,9 @@ export default class Connection {
387387 this . _log . debug ( `${ this } closing` ) ;
388388 }
389389
390- if ( this . _protocol ) {
391- // protocol has been initialized
392- // use it to notify the database about the upcoming close of the connection
390+ if ( this . _protocol && this . isOpen ( ) ) {
391+ // protocol has been initialized and this connection is healthy
392+ // notify the database about the upcoming close of the connection
393393 this . _protocol . prepareToClose ( NO_OP_OBSERVER ) ;
394394 }
395395
Original file line number Diff line number Diff line change @@ -367,6 +367,27 @@ describe('Connection', () => {
367367 } ) . catch ( done . fail ) ;
368368 } ) ;
369369
370+ it ( 'should not prepare broken connection to close' , done => {
371+ connection = createConnection ( 'bolt://localhost' ) ;
372+
373+ connection . connect ( 'my-connection/9.9.9' , basicAuthToken ( ) )
374+ . then ( ( ) => {
375+ expect ( connection . _protocol ) . toBeDefined ( ) ;
376+ expect ( connection . _protocol ) . not . toBeNull ( ) ;
377+
378+ // make connection seem broken
379+ connection . _isBroken = true ;
380+ expect ( connection . isOpen ( ) ) . toBeFalsy ( ) ;
381+
382+ connection . _protocol . prepareToClose = ( ) => {
383+ throw new Error ( 'Not supposed to be called' ) ;
384+ } ;
385+
386+ connection . close ( ( ) => done ( ) ) ;
387+ } )
388+ . catch ( error => done . fail ( error ) ) ;
389+ } ) ;
390+
370391 function packedHandshakeMessage ( ) {
371392 const result = alloc ( 4 ) ;
372393 result . putInt32 ( 0 , 1 ) ;
You can’t perform that action at this time.
0 commit comments