Skip to content

Commit

Permalink
handle connect() timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
zweifisch committed Jun 30, 2015
1 parent 72784e0 commit 76bd2fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ function connect(url, socketOptions, openCallback) {
function onConnect() {
sockok = true;
sock.setNoDelay(noDelay);
if (timeout) {
sock.setTimeout(
timeout, openCallback.bind(this, new Error('connect ETIMEDOUT')));
}
if (keepAlive) sock.setKeepAlive(keepAlive, keepAliveDelay);

var c = new Connection(sock);
Expand All @@ -162,6 +158,11 @@ function connect(url, socketOptions, openCallback) {
throw new Error("Expected amqp: or amqps: as the protocol; got " + protocol);
}

if (timeout) {
sock.setTimeout(
timeout, openCallback.bind(this, new Error('connect ETIMEDOUT')));
}

sock.once('error', function(err) {
if (!sockok) openCallback(err);
});
Expand Down

0 comments on commit 76bd2fb

Please sign in to comment.