Skip to content

Commit

Permalink
Merge pull request #290 from luin/fix/connection-error
Browse files Browse the repository at this point in the history
fix: fix wrong host not causing error
  • Loading branch information
luin committed Apr 30, 2016
2 parents 4e4f5e2 + 25c300e commit 02eb721
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ Redis.prototype.connect = function (callback) {
stream.setTimeout(_this.options.connectTimeout, function () {
stream.setTimeout(0);
stream.destroy();

var err = new Error('connect ETIMEDOUT');
err.errorno = 'ETIMEDOUT';
err.code = 'ETIMEDOUT';
err.syscall = 'connect';
eventHandler.errorHandler(_this)(err);
});
stream.once(CONNECT_EVENT, function () {
stream.setTimeout(0);
Expand Down
11 changes: 10 additions & 1 deletion test/functional/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ describe('connection', function () {
connectTimeout: 1,
retryStrategy: null
});
var pending = 2;
redis.on('error', function (err) {
expect(err.message).to.eql('connect ETIMEDOUT');
if (!--pending) {
done();
}
});
redis.get('foo', function (err) {
expect(err.message).to.match(/Connection is closed/);
done();
if (!--pending) {
done();
}
});
});

Expand Down

0 comments on commit 02eb721

Please sign in to comment.