Skip to content

Commit

Permalink
2.17.4 - Add connectTimeout option to cancel connect if there is no s…
Browse files Browse the repository at this point in the history
…ocket.
  • Loading branch information
JohanvdWest committed Mar 24, 2017
1 parent b06bb5a commit 01069ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/client/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,14 @@

this.__connecting = true;

var connectTimeout = setTimeout(function () {
callback(new Error("Timed out waiting for connection"));
}, this.options.connectTimeout || 10000);

this.pubsub = this.__getConnection();

this.pubsub.on('open', function waitForConnection() {
clearTimeout(connectTimeout);
_this.__connecting = false;
_this.pubsub.removeListener('open', waitForConnection);
_this.login(callback);
Expand All @@ -581,6 +586,7 @@
// ERROR before connected,
// ECONNREFUSED etc. out as errors on callback
_this.__connecting = false;
clearTimeout(connectTimeout);
return callback(e);
}
_this.handle_error(e);
Expand Down Expand Up @@ -1093,7 +1099,7 @@
else {
setTimeout(function () {
destroyPubSub(_this, callback); // we need to give Primus a cycle to clean up for socket level errors
},0);
}, 0);
}

});
Expand Down
5 changes: 2 additions & 3 deletions test/b8_security_https_websockets_sanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,8 @@ describe('b8_security_https_websockets_sanity', function () {
});
});

// this test does not pass in 0.10
it.skip('fails to connect on http and the client is destroyed', function (done) {
happn_client.create({config: {protocol: 'http'}, testMode: true}, function (e) {
it('fails to connect on http and the client is destroyed', function (done) {
happn_client.create({config: {protocol: 'http'}, testMode: true, connectTimeout:1000}, function (e) {
expect(e).to.be.an('object');
expect(happn_client.lastClient).to.be.an('object');
expect(happn_client.lastClient).to.have.property('options');
Expand Down

0 comments on commit 01069ce

Please sign in to comment.