Skip to content

Commit

Permalink
Disable the timeout once connection is successful
Browse files Browse the repository at this point in the history
Since it's a TCP timeout, it might apply after the AMQP connection has
been established, but we don't want to be calling the openCallback at
that point.

(Also changed the condition for having a timeout: we care about
defined, non-zero values.)
  • Loading branch information
squaremo committed Jan 10, 2015
1 parent e9ec151 commit 7ccd837
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ function connect(url, socketOptions, openCallback) {
sockok = true;
sock.setNoDelay(noDelay);

if (typeof timeout !== 'undefined') {
sock.setTimeout(timeout, function() {
openCallback(new Error('connect ETIMEDOUT'));
});
if (timeout) {
sock.setTimeout(timeout, function() {
openCallback(new Error('connect ETIMEDOUT'));
});
}

var c = new Connection(sock);
c.open(fields, function(err, ok) {
if (err === null) openCallback(null, c);
// disable timeout once the connection is open, we don't want
// it fouling things
if (timeout) sock.setTimeout(0);
if (err === null) {
openCallback(null, c);
}
else openCallback(err);
});
}
Expand Down

0 comments on commit 7ccd837

Please sign in to comment.