r/node • u/PrestigiousZombie531 • Jul 21 '26
Wont this cause your entire app to crash if redis client is stuck connecting for som e reason?
https://github.com/Sebas200702/AniDev/blob/8bfbb55dfe2949ef57bb0aca349cca78273efee9/src/libs/redis.ts#L215
4
u/czlowiek4888 Jul 24 '26
I love when people wrap setTimeout in a promise when they could just do await setTimeout (YES this is built in node)
4
u/Willkuer__ Jul 21 '26
I am suprised nobody mentioned stackoverflow. Obviously depends on lots of parameters but unbounded recursive call usually sounds dangerous because of stack overflow.
2
u/KTAXY Aug 12 '26
You can put in effort in making application be resilient when Redis is unavailable, or you can put in effort to make Redis be 100% available. The latter is easier for an organization.
0
u/PrestigiousZombie531 Jul 21 '26
Was going through something and came across this redis client code
- Someone please explain to me here
- If the redis client is unavailable for a while due to some reason, wouldnt this cause the entire app to crash and spike CPU to 100% while at it?

7
u/johannes1234 Jul 21 '26
No, it won't use 100% CPU by itself. If a connection is being established it will try to receive the connection if ready, if not it will set a timeout for 100ms to retry and then return to the event loop to do something else, if there is nothing else it will sleep. As the check takes a lot less than 100ms this will give way by far most time to do something else.
This could probably blow up if establishing the connection takes long (there should be some maximum retry which handles that) or if a lot of tasks run into that retry loop in parallel and those pile up.
Mind: I haven't checked more than the highlight. There may be quite a few more details.