File tree Expand file tree Collapse file tree
neo4j-driver-deno/lib/bolt-connection/channel Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ export default class WebSocketChannel {
168168 return new Promise ( ( resolve , reject ) => {
169169 if ( this . _ws && this . _ws . readyState !== WS_CLOSED ) {
170170 this . _open = false
171+ this . stopReceiveTimeout ( )
171172 this . _clearConnectionTimeout ( )
172173 this . _ws . onclose = ( ) => resolve ( )
173174 this . _ws . close ( )
@@ -206,7 +207,7 @@ export default class WebSocketChannel {
206207 * Start the receive timeout for the channel.
207208 */
208209 startReceiveTimeout ( ) {
209- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210211 this . _receiveTimeoutStarted = true
211212 this . _resetTimeout ( )
212213 }
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export default class DenoChannel {
150150 async close ( ) {
151151 if ( this . _open ) {
152152 this . _open = false
153+ this . stopReceiveTimeout ( )
153154 if ( this . _conn != null ) {
154155 await this . _conn . close ( )
155156 }
@@ -185,7 +186,7 @@ export default class DenoChannel {
185186 * Start the receive timeout for the channel.
186187 */
187188 startReceiveTimeout ( ) {
188- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189190 this . _receiveTimeoutStarted = true
190191 this . _resetTimeout ( )
191192 }
Original file line number Diff line number Diff line change @@ -412,6 +412,31 @@ describe('WebSocketChannel', () => {
412412 expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
413413 } )
414414
415+ it ( 'should be cleared when connection closes' , async ( ) => {
416+ webSocketChannel . startReceiveTimeout ( )
417+
418+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
419+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 1 )
420+ expect ( fakeSetTimeout . calls [ 0 ] [ 1 ] ) . toEqual ( receiveTimeout )
421+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
422+
423+ await webSocketChannel . close ( )
424+
425+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 1 )
426+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 1 )
427+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ 0 ] )
428+ } )
429+
430+ it ( 'should call not setTimeout(receiveTimeout) when connection is closed' , async ( ) => {
431+ await webSocketChannel . close ( )
432+
433+ webSocketChannel . startReceiveTimeout ( )
434+
435+ expect ( fakeSetTimeout . _timeoutIdCounter ) . toEqual ( 0 )
436+ expect ( fakeSetTimeout . calls . length ) . toEqual ( 0 )
437+ expect ( fakeSetTimeout . clearedTimeouts ) . toEqual ( [ ] )
438+ } )
439+
415440 it ( 'should call setTimeout(receiveTimeout) after stopped' , ( ) => {
416441 webSocketChannel . startReceiveTimeout ( )
417442
Original file line number Diff line number Diff line change @@ -168,6 +168,7 @@ export default class WebSocketChannel {
168168 return new Promise ( ( resolve , reject ) => {
169169 if ( this . _ws && this . _ws . readyState !== WS_CLOSED ) {
170170 this . _open = false
171+ this . stopReceiveTimeout ( )
171172 this . _clearConnectionTimeout ( )
172173 this . _ws . onclose = ( ) => resolve ( )
173174 this . _ws . close ( )
@@ -206,7 +207,7 @@ export default class WebSocketChannel {
206207 * Start the receive timeout for the channel.
207208 */
208209 startReceiveTimeout ( ) {
209- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
210211 this . _receiveTimeoutStarted = true
211212 this . _resetTimeout ( )
212213 }
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ export default class DenoChannel {
150150 async close ( ) {
151151 if ( this . _open ) {
152152 this . _open = false
153+ this . stopReceiveTimeout ( )
153154 if ( this . _conn != null ) {
154155 await this . _conn . close ( )
155156 }
@@ -185,7 +186,7 @@ export default class DenoChannel {
185186 * Start the receive timeout for the channel.
186187 */
187188 startReceiveTimeout ( ) {
188- if ( this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189+ if ( this . _open && this . _receiveTimeout !== null && ! this . _receiveTimeoutStarted ) {
189190 this . _receiveTimeoutStarted = true
190191 this . _resetTimeout ( )
191192 }
You can’t perform that action at this time.
0 commit comments