diff --git a/README.md b/README.md
index 0da36268..ca6084e2 100644
--- a/README.md
+++ b/README.md
@@ -553,7 +553,7 @@ ready | If `enableReadyCheck` is `true`, client will emit `ready` when the se
error | emits when an error occurs while connecting.
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.
@@ -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
-
 luin |  dguo |  shaharmor |  doublesharp |  nakulgan |
 AVVS |  ramonsnir |  hayeah |  albin3 |  phlip9 |
 fracmak |  ddunkin |  suprememoocow |  jpallen |  lpinca |
 jeffjen |  devaos |  9point6 |  horx |  ColmHally |
 klinquist |  alsotang |  zhuangya |  jcperez |  Gerhut |
 pensierinmusica |  TeeAaTeeUu |  igrcic |  ArtskydJ |  tkalfigo |
 mtlima |  devoto13 |  VikramTiwari |  henstock |  stipsan |
 pra85 |  i5ting |  nswbmw |  joeledwards |  pyros2097 |
+ luin |  dguo |  shaharmor |  doublesharp |  nakulgan |
 AVVS |  ramonsnir |  hayeah |  albin3 |  phlip9 |
 fracmak |  ddunkin |  suprememoocow |  jpallen |  lpinca |
 jeffjen |  devaos |  headquarters |  9point6 |  horx |
 darrachequesne |  klinquist |  ColmHally |  alsotang |  zhuangya |
 jcperez |  Gerhut |  TeeAaTeeUu |  pensierinmusica |  devoto13 |
 pyros2097 |  tkalfigo |  mtlima |  igrcic |  henstock |
 pra85 |  VikramTiwari |  nswbmw |  joeledwards |  stipsan |
 i5ting |  ArtskydJ |
# License
diff --git a/lib/connectors/connector.js b/lib/connectors/connector.js
index 1b7f9892..4a5abbd5 100644
--- a/lib/connectors/connector.js
+++ b/lib/connectors/connector.js
@@ -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);
});
diff --git a/lib/redis.js b/lib/redis.js
index f24f687a..bf043c0f 100644
--- a/lib/redis.js
+++ b/lib/redis.js
@@ -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';
diff --git a/test/functional/sentinel.js b/test/functional/sentinel.js
index 88671c13..b8e66352 100644
--- a/test/functional/sentinel.js
+++ b/test/functional/sentinel.js
@@ -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();