Skip to content

Commit 25c300e

Browse files
committed
fix: fix wrong host not causing error
Close #287
1 parent 4e4f5e2 commit 25c300e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/redis.js

+6
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ Redis.prototype.connect = function (callback) {
276276
stream.setTimeout(_this.options.connectTimeout, function () {
277277
stream.setTimeout(0);
278278
stream.destroy();
279+
280+
var err = new Error('connect ETIMEDOUT');
281+
err.errorno = 'ETIMEDOUT';
282+
err.code = 'ETIMEDOUT';
283+
err.syscall = 'connect';
284+
eventHandler.errorHandler(_this)(err);
279285
});
280286
stream.once(CONNECT_EVENT, function () {
281287
stream.setTimeout(0);

test/functional/connection.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,18 @@ describe('connection', function () {
4848
connectTimeout: 1,
4949
retryStrategy: null
5050
});
51+
var pending = 2;
52+
redis.on('error', function (err) {
53+
expect(err.message).to.eql('connect ETIMEDOUT');
54+
if (!--pending) {
55+
done();
56+
}
57+
});
5158
redis.get('foo', function (err) {
5259
expect(err.message).to.match(/Connection is closed/);
53-
done();
60+
if (!--pending) {
61+
done();
62+
}
5463
});
5564
});
5665

0 commit comments

Comments
 (0)