-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ConnectionTimeoutError: Connection timeout #1656
Comments
Can you please share the configuration you send to |
Sorry @leibale for the late response. Actually, I did just as mentioned in the docs:
I realized that the error is thrown in these cases:
|
I'm having the same problem. Using node-redis 4.0.0
|
import { createClient } from 'redis';
const client = createClient({ url: 'redis://localhost:6379' });
await client.connect();
await client.ping();
await client.disconnect(); works for me (the classic answer :P)... wanna debug it together? |
I reproduced this issue in two different projects, but I find it difficult to reproduce it on a basic server, If you want we can debug it together 👍 |
Hello, We had this issue on our project. The root cause is that we try to |
you are right, Should not be used .connect when using createcluster api |
Hi so, what's the fix? |
I am facing the same issue as a result of upgrading from v3 to v4. Everything is working just fine, so I am little confused as to why I'm seeing the error. @Chocobozzz how did you find out about this? And I am also a bit perplexed by the node loop being blocked with sync calls. I mean, how do you know which requires are sync, and which aren't? |
@aarhusgregersen All requires are sync. You can profile your application using chrome |
The fix here is to increase the timout of the socket as follow:
|
@menocomp great suggestion! However, to my knowledge, I am not using a cluster and I therefore don't think the solution applies to me :-( |
Hi, |
That's great @Raraku ! Thank you. I have the same restrictions, so perhaps this will work for me too. I will confirm and get back. |
Running the command |
What is the fix for this I am using it in TS and sometimes it work and sometimes this error comes |
same Problem here ... connection timeout on my windows 10 dev machine |
i think it may be related to redis configuration in the protected Mode
|
on further investigation i tried binding to all interfaces instead of loopback, leaving protected mode on ... this is working so far
|
Got the may Be, According to me this is issue because of race condition of async tasks. So to overcome that we can just go with await or we can connect to socket or server after redisClient.connect().then(() => {
// other tasks
}) May be this solves issues then I am glad. |
Unfortunately i couldn't resolve this issue |
I also had to switch to Switching to |
@kabapy @maximilize The ConnectionTimeout error is thrown by the underlying node.js socket API, (both packages call |
I think this behavior should be implemented in this lib. Not in my code! |
@kabapy it is implemented, it's emitting an 'error' to let you know something is not working as expected, it does not means the client is not reconnecting.. What do you prefer:
BTW, one difference between the packages that I've found now is the default |
@leibale that is correct, but I couldn't catch this error in my try...catch block. I end up with a hanging process or a crashed one if my app is dependant on redis and can't run without it. Even with pm2 I couldn't remedy this issue with automatic restart. I used the lib in a project 2 years ago, and I never faced this issue on the same system. I don't know if it is an issue related to specific node version or a lib implementation problem. I agree with you that the developer should know that a problem has occured. But this problem should be catched and corrected either by the library or the user. With the unpredictable behavior of the problem and the absence of a working solution, we had no course of action except switching to another lib. |
@kabapy in order to catch this error you gave to handle Before calling BTW, there is already an issue + PR to add a note to the docs (#2302). |
@leibale I did try that and even tried wrapping it in async function and use try catch block. it do sometime catch the error and I have to terminate the process because the app can't run without redis. Sometime it just hangs. I am sorry, the problem is indeed tricky. I wish I could be of more help. I remembered now that my old project used the redis library indirectly through socket.io.redis 5.2.0 lib. And it never failed to connect |
@kabapy you had an error listener and the app still exists with "Connection Timeout" error? This should be impossible.. you have a code to reproduce the error maybe? "Try catch" won't catch event based errors |
@leibale I am sorry that project is not active right now. I didn't use any fancy setup. Just followed documentation. It just connected to mongo and redis before starting the http server. I used redis mainly as a caching layer. As I described.. The problem is unpredictable some days it didn't happen during development and some days I spent half an hour restarting and tinkering with redis server. I managed to reproduce the issue during beta testing, On windows 2016 server environment. I hoped that it was my dev machine that caused the issue, But I was wrong. In this thread many decribed having similar issue with the library. I hope some of them can shed some light on this issue. Again, I am sorry, I wish i can be of more help |
I'm using the error listener also for the I suspect there is a weird error somewhere. If it may help, we use URL's as connection string like |
@maximilize wanna have a quick meeting and show me the error? I tried to reproduce it so many times but never manage to do it, if you'll be able to help it'll be amazing! I'll wait in this meeting for the next 30 minutes. edit:
|
@leibale Did you managed to solved it? |
@ManarArabi I didn't manage to reproduce it even.. do you get this error? Can you help me reproduce it? |
@leibale for me after several hours of debugging, it worked after I connect with the IP directly and increase the timeout to 50000
|
@ManarArabi 50 seconds to connect?! I think that your event loop is blocked for too long on startup, that's why you get these errors. See this comment. BTW, I'm pretty sure that connecting to the IP/hostname will give the same result, can you try with |
Has anyone here tried using the createClient({
url: "redis://localhost:6379",
pingInterval: 1000,
}) I am using node-redis (via redis-om) with Deno+Fresh, and a clean Redis Stack container running in a local Docker. Here's what I did, it seems to have solved the issue for now. Hope this helps someone. import { Client } from "npm:redis-om"
import { createClient } from "npm:redis"
const nodeClient = createClient({
url: "redis://localhost:6379",
pingInterval: 1000,
})
await nodeClient.connect()
const omClient = new Client()
const redis = await omClient.use(nodeClient)
export { redis } |
Adding |
@leibale this issue is still labelled "Pending Author Input"; is that still relevant? |
I don't know how, but |
@younes-io We need a way to reproduce the issue... |
It's definitely odd - we have had a redis cache implemented in our production environment for many months and no issue there... we added a cache to our non-prod environments a week ago and no issues with it until today... this is running in AWS on Kubernetes (EKS) with Redis (Elasticache). Some pods were starting up fine first try, others after one or two attempts, some went into Certainly doesn't seem trivial to recreate reliably in our usage at least. The |
I am running into the same problem but only in my unit tests. I believe I have found the issue. Just have no idea how to work around it. import { createClient } from "redis";
jest.useFakeTimers(); // <<-- THIS MAKES REDIS NEVER CONNECT. Remove it and the test passes.
describe("redis", () => {
it("connect to redis", async () => {
const redis = createClient({
url: 'redis://localhost:6379/2'
});
await redis.connect();
const thing = await redis.set('myKey', 'myValue');
expect(thing).not.toBeNull();
redis.quit();
});
});
|
If it makes you feel any better I just tried the same test with |
So its a Jest problem. Specifically with the fake timers in any version > 27.
Have to use "legacy" now or everything locks up. |
In my case, I was getting the Changing it to reference the explicit IPv4 address |
I feel like this is either a bug or rather a documentation issue. For me as I want to migrate from v3 to v4 - I did get the timeout error as well, when I tried to use the official documentation like this: const clientTimeout = redis.createClient({
password: '*****',
socket: {
port: 6379,
host: '127.0.0.1',
tls: true
}
}); But when I use the following code (with non-documented properties), the client does connect. const clientWORKING = redis.createClient({
host: '127.0.0.1',
port: 6379,
password: '*****',
tls : true
}); So I would argue, that the documentation is not listing tls, host and port as root properties correctly. The above code was run in a node test project using redis version 4.6.7 |
I have also stumbled on to this only when using Jest (29) jest.useFakeTimers({
doNotFake: ['nextTick', 'performance', 'queueMicrotask']
}) |
This also happened for us when mocking time. For some reason the error only occurred in ci/cd server which has different timezone. This thread helped to figure out the following workaround:
|
const client = redis.createClient({ This works for me, I am using azure cache service - Redis version 6 |
Since Node 23.0, |
I get this error and I don't understand why:
How do I get more details about this:
Environment
The text was updated successfully, but these errors were encountered: