Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled error event: Error: connect EHOSTDOWN #1209

Closed
OPScorp opened this issue Oct 16, 2020 · 3 comments · Fixed by #1299
Closed

Unhandled error event: Error: connect EHOSTDOWN #1209

OPScorp opened this issue Oct 16, 2020 · 3 comments · Fixed by #1299
Labels

Comments

@OPScorp
Copy link

OPScorp commented Oct 16, 2020

Hi,
I am getting Error: connect EHOSTDOWN and terminating of server process when connecting to unavailable Redis server.
Sometimes on start and sometimes on reconnecting try.

Problem in this file: StandaloneConnector.js
in function connect.

process.nextTick(() => {
if (!this.connecting) {
reject(new Error(utils_1.CONNECTION_CLOSED_ERROR_MSG));
return;
}
try {
if (options.tls) {
this.stream = tls_1.connect(connectionOptions);
}
else {
this.stream = net_1.createConnection(connectionOptions);
}
// Need to add this code!!
this.stream.once("error", err => {
reject(err);
});
}
catch (err) {
reject(err);
return;
}
resolve(this.stream);
});

P.S.: this is final fix. Hope help someone with this.

@peteraw77
Copy link

Is there any reason you haven't made a PR with this change? It solved the issue for me and I think it would be good to bring it to the maintainer's attention.

@andywelters
Copy link

I have the same issue. Let's make a PR.

luin added a commit that referenced this issue Mar 10, 2021
Currently, a stream (ex `net.Socket`) is returned via a Promise, and error
handlers are attached to the stream in the Promise callback.

However, if the errors are thrown immediately (ex with `process.nextTick()`),
the error handlers will not have the chance to attach to the stream, thus
unhandled error events will be thrown.

This PR makes all connectors resolve a factory instead of the created stream,
so the event handlers can be attached in the same tick.

Closes #1236
Closes #1209
Closes #1289
@ioredis-robot
Copy link
Collaborator

🎉 This issue has been resolved in version 4.24.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants