skip to Main Content

We are using redis version – 6.2.7 in Google Cloud Platform and node-redis package version – 4.6.7 . We are getting the below error in our Node.js 16 server in Google app engine.

ConnectionTimeoutError: Connection timeout
    at Socket.<anonymous> (/workspace/node_modules/@redis/client/dist/lib/client/socket.js:178:124)
    at Object.onceWrapper (node:events:627:28)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at Socket._onTimeout (node:net:550:8)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

Code snippet for connecting the redis is below.

this.client = redis.createClient({
      socket: { host: redisHost, port: REDISPORT},
    });
    this.client.connect();
    this.client.on("error", (err) => log.error("Error in redis :", err));

We also tried configuring connectTimeout for 10 seconds in the createClient after that we didn’t get this error. Should we have to configure the timeout ?
Can we have a proper solution or a work around for this Connection Timeout Error?

2

Answers


  1. You can test if this port open for your network:

    $ telnet <ip_address> <port_number>
    
    $ telnet <domain_name> <port_number>
    
    Login or Signup to reply.
  2. You could try this piece of code

    const client = redis.createClient({ 
        legacyMode: false, 
        socket: {
            connectTimeout: 10000
        }
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search