Skip to content

Commit

Permalink
Merge pull request #324 from deepstreamIO/fix/closed-not-error
Browse files Browse the repository at this point in the history
heartbeat missed should close connection
  • Loading branch information
yasserf committed Feb 19, 2017
2 parents f091f1d + e2c1b38 commit 0021b96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/message/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,11 @@ Connection.prototype._checkHeartBeat = function() {

if( Date.now() - this._lastHeartBeat > heartBeatTolerance ) {
clearInterval( this._heartbeatInterval );
this._client._$onError(
C.TOPIC.CONNECTION,
C.EVENT.CONNECTION_ERROR,
'heartbeat not received in the last ' + heartBeatTolerance + ' milliseconds' );
this._endpoint.close();
this._onError( 'Two connections heartbeats missed successively' );
}
};

Expand Down
4 changes: 2 additions & 2 deletions test-unit/unit/message/connectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ describe('connects - heartbeats', function(){
it( 'when it misses two heart beats it closes connection', function( done ){
setTimeout( function() {
expect( connection._endpoint.lastSendMessage ).toBe( null );
expect( connection.getState() ).toBe( 'ERROR' );
expect( clientMock.lastError ).toEqual( [ 'C', 'connectionError', 'Two connections heartbeats missed successively' ] );
expect( connection.getState() ).toBe( 'CLOSED' );
expect( clientMock.lastError ).toEqual( [ 'C', 'connectionError', 'heartbeat not received in the last 100 milliseconds' ] );
done();
}, 200 );
});
Expand Down

0 comments on commit 0021b96

Please sign in to comment.