Skip to content

Commit 904f433

Browse files
committed
fix: handle error when creating tls connection
1 parent bbab295 commit 904f433

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ ready | If `enableReadyCheck` is `true`, client will emit `ready` when the se
553553
error | emits when an error occurs while connecting.<br>However, ioredis emits all `error` events silently (only emits when there's at least one listener) so that your application won't crash if you're not listening to the `error` event.
554554
close | emits when an established Redis server connection has closed.
555555
reconnecting | emits after `close` when a reconnection will be made. The argument of the event is the time (in ms) before reconnecting.
556-
end | emits after `close` when no more reconnections will be made.
556+
end | emits after `close` when no more reconnections will be made, or the connection is failed to establish.
557557

558558
You can also check out the `Redis#status` property to get the current connection status.
559559

@@ -959,7 +959,7 @@ I'm happy to receive bug reports, fixes, documentation enhancements, and any oth
959959
And since I'm not a native English speaker, if you find any grammar mistakes in the documentation, please also let me know. :)
960960

961961
# Contributors
962-
<table><tr><td width="20%"><a href="https://github.com/luin"><img src="https://avatars.githubusercontent.com/u/635902?v=3" /></a><p align="center">luin</p></td><td width="20%"><a href="https://github.com/dguo"><img src="https://avatars.githubusercontent.com/u/2763135?v=3" /></a><p align="center">dguo</p></td><td width="20%"><a href="https://github.com/shaharmor"><img src="https://avatars.githubusercontent.com/u/10861920?v=3" /></a><p align="center">shaharmor</p></td><td width="20%"><a href="https://github.com/doublesharp"><img src="https://avatars.githubusercontent.com/u/571472?v=3" /></a><p align="center">doublesharp</p></td><td width="20%"><a href="https://github.com/nakulgan"><img src="https://avatars.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</p></td></tr><tr><td width="20%"><a href="https://github.com/AVVS"><img src="https://avatars.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td><td width="20%"><a href="https://github.com/ramonsnir"><img src="https://avatars.githubusercontent.com/u/1024028?v=3" /></a><p align="center">ramonsnir</p></td><td width="20%"><a href="https://github.com/hayeah"><img src="https://avatars.githubusercontent.com/u/50120?v=3" /></a><p align="center">hayeah</p></td><td width="20%"><a href="https://github.com/albin3"><img src="https://avatars.githubusercontent.com/u/6190670?v=3" /></a><p align="center">albin3</p></td><td width="20%"><a href="https://github.com/phlip9"><img src="https://avatars.githubusercontent.com/u/918989?v=3" /></a><p align="center">phlip9</p></td></tr><tr><td width="20%"><a href="https://github.com/fracmak"><img src="https://avatars.githubusercontent.com/u/378178?v=3" /></a><p align="center">fracmak</p></td><td width="20%"><a href="https://github.com/ddunkin"><img src="https://avatars.githubusercontent.com/u/264744?v=3" /></a><p align="center">ddunkin</p></td><td width="20%"><a href="https://github.com/suprememoocow"><img src="https://avatars.githubusercontent.com/u/594566?v=3" /></a><p align="center">suprememoocow</p></td><td width="20%"><a href="https://github.com/jpallen"><img src="https://avatars.githubusercontent.com/u/31305?v=3" /></a><p align="center">jpallen</p></td><td width="20%"><a href="https://github.com/lpinca"><img src="https://avatars.githubusercontent.com/u/1443911?v=3" /></a><p align="center">lpinca</p></td></tr><tr><td width="20%"><a href="https://github.com/jeffjen"><img src="https://avatars.githubusercontent.com/u/5814507?v=3" /></a><p align="center">jeffjen</p></td><td width="20%"><a href="https://github.com/devaos"><img src="https://avatars.githubusercontent.com/u/5412167?v=3" /></a><p align="center">devaos</p></td><td width="20%"><a href="https://github.com/9point6"><img src="https://avatars.githubusercontent.com/u/627697?v=3" /></a><p align="center">9point6</p></td><td width="20%"><a href="https://github.com/horx"><img src="https://avatars.githubusercontent.com/u/1332618?v=3" /></a><p align="center">horx</p></td><td width="20%"><a href="https://github.com/ColmHally"><img src="https://avatars.githubusercontent.com/u/20333?v=3" /></a><p align="center">ColmHally</p></td></tr><tr><td width="20%"><a href="https://github.com/klinquist"><img src="https://avatars.githubusercontent.com/u/1343376?v=3" /></a><p align="center">klinquist</p></td><td width="20%"><a href="https://github.com/alsotang"><img src="https://avatars.githubusercontent.com/u/1147375?v=3" /></a><p align="center">alsotang</p></td><td width="20%"><a href="https://github.com/zhuangya"><img src="https://avatars.githubusercontent.com/u/499038?v=3" /></a><p align="center">zhuangya</p></td><td width="20%"><a href="https://github.com/jcperez"><img src="https://avatars.githubusercontent.com/u/4073359?v=3" /></a><p align="center">jcperez</p></td><td width="20%"><a href="https://github.com/Gerhut"><img src="https://avatars.githubusercontent.com/u/2500247?v=3" /></a><p align="center">Gerhut</p></td></tr><tr><td width="20%"><a href="https://github.com/pensierinmusica"><img src="https://avatars.githubusercontent.com/u/3594037?v=3" /></a><p align="center">pensierinmusica</p></td><td width="20%"><a href="https://github.com/TeeAaTeeUu"><img src="https://avatars.githubusercontent.com/u/997511?v=3" /></a><p align="center">TeeAaTeeUu</p></td><td width="20%"><a href="https://github.com/igrcic"><img src="https://avatars.githubusercontent.com/u/394398?v=3" /></a><p align="center">igrcic</p></td><td width="20%"><a href="https://github.com/ArtskydJ"><img src="https://avatars.githubusercontent.com/u/1833684?v=3" /></a><p align="center">ArtskydJ</p></td><td width="20%"><a href="https://github.com/tkalfigo"><img src="https://avatars.githubusercontent.com/u/3481553?v=3" /></a><p align="center">tkalfigo</p></td></tr><tr><td width="20%"><a href="https://github.com/mtlima"><img src="https://avatars.githubusercontent.com/u/9111440?v=3" /></a><p align="center">mtlima</p></td><td width="20%"><a href="https://github.com/devoto13"><img src="https://avatars.githubusercontent.com/u/823594?v=3" /></a><p align="center">devoto13</p></td><td width="20%"><a href="https://github.com/VikramTiwari"><img src="https://avatars.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</p></td><td width="20%"><a href="https://github.com/henstock"><img src="https://avatars.githubusercontent.com/u/13809467?v=3" /></a><p align="center">henstock</p></td><td width="20%"><a href="https://github.com/stipsan"><img src="https://avatars.githubusercontent.com/u/81981?v=3" /></a><p align="center">stipsan</p></td></tr><tr><td width="20%"><a href="https://github.com/pra85"><img src="https://avatars.githubusercontent.com/u/829526?v=3" /></a><p align="center">pra85</p></td><td width="20%"><a href="https://github.com/i5ting"><img src="https://avatars.githubusercontent.com/u/3118295?v=3" /></a><p align="center">i5ting</p></td><td width="20%"><a href="https://github.com/nswbmw"><img src="https://avatars.githubusercontent.com/u/4279697?v=3" /></a><p align="center">nswbmw</p></td><td width="20%"><a href="https://github.com/joeledwards"><img src="https://avatars.githubusercontent.com/u/412853?v=3" /></a><p align="center">joeledwards</p></td><td width="20%"><a href="https://github.com/pyros2097"><img src="https://avatars.githubusercontent.com/u/1687946?v=3" /></a><p align="center">pyros2097</p></td></tr></table>
962+
<table><tr><td width="20%"><a href="https://github.com/luin"><img src="https://avatars.githubusercontent.com/u/635902?v=3" /></a><p align="center">luin</p></td><td width="20%"><a href="https://github.com/dguo"><img src="https://avatars.githubusercontent.com/u/2763135?v=3" /></a><p align="center">dguo</p></td><td width="20%"><a href="https://github.com/shaharmor"><img src="https://avatars.githubusercontent.com/u/10861920?v=3" /></a><p align="center">shaharmor</p></td><td width="20%"><a href="https://github.com/doublesharp"><img src="https://avatars.githubusercontent.com/u/571472?v=3" /></a><p align="center">doublesharp</p></td><td width="20%"><a href="https://github.com/nakulgan"><img src="https://avatars.githubusercontent.com/u/189836?v=3" /></a><p align="center">nakulgan</p></td></tr><tr><td width="20%"><a href="https://github.com/AVVS"><img src="https://avatars.githubusercontent.com/u/1713617?v=3" /></a><p align="center">AVVS</p></td><td width="20%"><a href="https://github.com/ramonsnir"><img src="https://avatars.githubusercontent.com/u/1024028?v=3" /></a><p align="center">ramonsnir</p></td><td width="20%"><a href="https://github.com/hayeah"><img src="https://avatars.githubusercontent.com/u/50120?v=3" /></a><p align="center">hayeah</p></td><td width="20%"><a href="https://github.com/albin3"><img src="https://avatars.githubusercontent.com/u/6190670?v=3" /></a><p align="center">albin3</p></td><td width="20%"><a href="https://github.com/phlip9"><img src="https://avatars.githubusercontent.com/u/918989?v=3" /></a><p align="center">phlip9</p></td></tr><tr><td width="20%"><a href="https://github.com/fracmak"><img src="https://avatars.githubusercontent.com/u/378178?v=3" /></a><p align="center">fracmak</p></td><td width="20%"><a href="https://github.com/ddunkin"><img src="https://avatars.githubusercontent.com/u/264744?v=3" /></a><p align="center">ddunkin</p></td><td width="20%"><a href="https://github.com/suprememoocow"><img src="https://avatars.githubusercontent.com/u/594566?v=3" /></a><p align="center">suprememoocow</p></td><td width="20%"><a href="https://github.com/jpallen"><img src="https://avatars.githubusercontent.com/u/31305?v=3" /></a><p align="center">jpallen</p></td><td width="20%"><a href="https://github.com/lpinca"><img src="https://avatars.githubusercontent.com/u/1443911?v=3" /></a><p align="center">lpinca</p></td></tr><tr><td width="20%"><a href="https://github.com/jeffjen"><img src="https://avatars.githubusercontent.com/u/5814507?v=3" /></a><p align="center">jeffjen</p></td><td width="20%"><a href="https://github.com/devaos"><img src="https://avatars.githubusercontent.com/u/5412167?v=3" /></a><p align="center">devaos</p></td><td width="20%"><a href="https://github.com/headquarters"><img src="https://avatars.githubusercontent.com/u/347079?v=3" /></a><p align="center">headquarters</p></td><td width="20%"><a href="https://github.com/9point6"><img src="https://avatars.githubusercontent.com/u/627697?v=3" /></a><p align="center">9point6</p></td><td width="20%"><a href="https://github.com/horx"><img src="https://avatars.githubusercontent.com/u/1332618?v=3" /></a><p align="center">horx</p></td></tr><tr><td width="20%"><a href="https://github.com/darrachequesne"><img src="https://avatars.githubusercontent.com/u/13031701?v=3" /></a><p align="center">darrachequesne</p></td><td width="20%"><a href="https://github.com/klinquist"><img src="https://avatars.githubusercontent.com/u/1343376?v=3" /></a><p align="center">klinquist</p></td><td width="20%"><a href="https://github.com/ColmHally"><img src="https://avatars.githubusercontent.com/u/20333?v=3" /></a><p align="center">ColmHally</p></td><td width="20%"><a href="https://github.com/alsotang"><img src="https://avatars.githubusercontent.com/u/1147375?v=3" /></a><p align="center">alsotang</p></td><td width="20%"><a href="https://github.com/zhuangya"><img src="https://avatars.githubusercontent.com/u/499038?v=3" /></a><p align="center">zhuangya</p></td></tr><tr><td width="20%"><a href="https://github.com/jcperez"><img src="https://avatars.githubusercontent.com/u/4073359?v=3" /></a><p align="center">jcperez</p></td><td width="20%"><a href="https://github.com/Gerhut"><img src="https://avatars.githubusercontent.com/u/2500247?v=3" /></a><p align="center">Gerhut</p></td><td width="20%"><a href="https://github.com/TeeAaTeeUu"><img src="https://avatars.githubusercontent.com/u/997511?v=3" /></a><p align="center">TeeAaTeeUu</p></td><td width="20%"><a href="https://github.com/pensierinmusica"><img src="https://avatars.githubusercontent.com/u/3594037?v=3" /></a><p align="center">pensierinmusica</p></td><td width="20%"><a href="https://github.com/devoto13"><img src="https://avatars.githubusercontent.com/u/823594?v=3" /></a><p align="center">devoto13</p></td></tr><tr><td width="20%"><a href="https://github.com/pyros2097"><img src="https://avatars.githubusercontent.com/u/1687946?v=3" /></a><p align="center">pyros2097</p></td><td width="20%"><a href="https://github.com/tkalfigo"><img src="https://avatars.githubusercontent.com/u/3481553?v=3" /></a><p align="center">tkalfigo</p></td><td width="20%"><a href="https://github.com/mtlima"><img src="https://avatars.githubusercontent.com/u/9111440?v=3" /></a><p align="center">mtlima</p></td><td width="20%"><a href="https://github.com/igrcic"><img src="https://avatars.githubusercontent.com/u/394398?v=3" /></a><p align="center">igrcic</p></td><td width="20%"><a href="https://github.com/henstock"><img src="https://avatars.githubusercontent.com/u/13809467?v=3" /></a><p align="center">henstock</p></td></tr><tr><td width="20%"><a href="https://github.com/pra85"><img src="https://avatars.githubusercontent.com/u/829526?v=3" /></a><p align="center">pra85</p></td><td width="20%"><a href="https://github.com/VikramTiwari"><img src="https://avatars.githubusercontent.com/u/1330677?v=3" /></a><p align="center">VikramTiwari</p></td><td width="20%"><a href="https://github.com/nswbmw"><img src="https://avatars.githubusercontent.com/u/4279697?v=3" /></a><p align="center">nswbmw</p></td><td width="20%"><a href="https://github.com/joeledwards"><img src="https://avatars.githubusercontent.com/u/412853?v=3" /></a><p align="center">joeledwards</p></td><td width="20%"><a href="https://github.com/stipsan"><img src="https://avatars.githubusercontent.com/u/81981?v=3" /></a><p align="center">stipsan</p></td></tr><tr><td width="20%"><a href="https://github.com/i5ting"><img src="https://avatars.githubusercontent.com/u/3118295?v=3" /></a><p align="center">i5ting</p></td><td width="20%"><a href="https://github.com/ArtskydJ"><img src="https://avatars.githubusercontent.com/u/1833684?v=3" /></a><p align="center">ArtskydJ</p></td></table>
963963

964964
# License
965965

lib/connectors/connector.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ Connector.prototype.connect = function (callback) {
3939
return;
4040
}
4141
var stream;
42-
if (_this.options.tls) {
43-
stream = tls.connect(connectionOptions);
44-
} else {
45-
stream = net.createConnection(connectionOptions);
42+
43+
try {
44+
if (_this.options.tls) {
45+
stream = tls.connect(connectionOptions);
46+
} else {
47+
stream = net.createConnection(connectionOptions);
48+
}
49+
} catch (err) {
50+
callback(err);
51+
return;
4652
}
53+
4754
_this.stream = stream;
4855
callback(null, stream);
4956
});

lib/redis.js

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Redis.prototype.connect = function (callback) {
268268
_this.flushQueue(err);
269269
_this.silentEmit('error', err);
270270
reject(err);
271+
_this.setStatus('end');
271272
return;
272273
}
273274
var CONNECT_EVENT = _this.options.tls ? 'secureConnect' : 'connect';

test/functional/sentinel.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ describe('sentinel', function () {
7474
finish();
7575
});
7676

77-
var pending = 2;
77+
redis.on('end', function () {
78+
finish();
79+
});
80+
81+
var pending = 3;
7882
function finish() {
7983
if (!--pending) {
8084
redis.disconnect();

0 commit comments

Comments
 (0)