Skip to content

Commit

Permalink
fix: handle error when creating tls connection
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Dec 4, 2016
1 parent bbab295 commit 904f433
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ ready | If `enableReadyCheck` is `true`, client will emit `ready` when the se
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.
close | emits when an established Redis server connection has closed.
reconnecting | emits after `close` when a reconnection will be made. The argument of the event is the time (in ms) before reconnecting.
end | emits after `close` when no more reconnections will be made.
end | emits after `close` when no more reconnections will be made, or the connection is failed to establish.

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

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

# Contributors
<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>
<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>

# License

Expand Down
15 changes: 11 additions & 4 deletions lib/connectors/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ Connector.prototype.connect = function (callback) {
return;
}
var stream;
if (_this.options.tls) {
stream = tls.connect(connectionOptions);
} else {
stream = net.createConnection(connectionOptions);

try {
if (_this.options.tls) {
stream = tls.connect(connectionOptions);
} else {
stream = net.createConnection(connectionOptions);
}
} catch (err) {
callback(err);
return;
}

_this.stream = stream;
callback(null, stream);
});
Expand Down
1 change: 1 addition & 0 deletions lib/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Redis.prototype.connect = function (callback) {
_this.flushQueue(err);
_this.silentEmit('error', err);
reject(err);
_this.setStatus('end');
return;
}
var CONNECT_EVENT = _this.options.tls ? 'secureConnect' : 'connect';
Expand Down
6 changes: 5 additions & 1 deletion test/functional/sentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ describe('sentinel', function () {
finish();
});

var pending = 2;
redis.on('end', function () {
finish();
});

var pending = 3;
function finish() {
if (!--pending) {
redis.disconnect();
Expand Down

0 comments on commit 904f433

Please sign in to comment.