RedisClient : Bun Application Stuck During Execution of RedisClient.connect() Function
Description
My bun application gets stuck when executing the function RedisClient.connect(). I want to catch the error immediately upon failure. But, It throws an error after about 2 minutes. Additionally, this issue only occurs when a request is made to a URL that does not respond, not to a non-existent URL.
I also think that 2 minutes is too long to wait before an error is thrown. Is there a way to adjust this interval?
I'm not sure if this issue also occurs in a Node environment.
Here's the code:
import { createClient } from "redis";
import { logger } from "../config/winston";
const redis_client = await createClient({
url: "redis://172.0.0.4:6379", // This URL does not respond.
}).on("error", (err: Error) => {
logger.error(`Redis client error`);
throw err;
});
logger.info("Connecting to redis client..."); // This works
await redis_client.connect().catch((err: Error) => { // Gets stuck here
logger.error(err);
throw err;
});
logger.info("Redis client connected"); // This doesn't execute
The logs are provided at the very bottom.
Node.js Version
Bun 1.0.3
Redis Server Version
7.2.1
Node Redis Version
4.6.10
Platform
Alpine linux 3.18.3
Logs
2023-10-17 04:48:54 info: Connecting to redis client...
2023-10-17 04:51:04 error: Redis client error
2023-10-17 04:51:04 error: undefined
ECONNREFUSED: Failed to connect
syscall: "connect"
@bong-u i found this issue because i ran into a similar error message
my problem involved docker-compose and a mis-configured redis url. passing redis://<docker-service-name>:6379 to the client config solved the problem for me. i think because the docker-compose service name stands in for the container ip
it sounds like your question is specifically RE redis configurability. the createClient config docs may have an answer for you: https://github.com/redis/node-redis/blob/d6d2064c72b99d34fc88318f3979177e3c89acd4/docs/client-configuration.md
sorry if i've misunderstood. i'm new to both bun and redis. could you add a little context/info about why you're throwing from both the error event handler and the connection catch? it's not totally clear to me from your code snippet what behavior you expect/would like to see