node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Timeout not being reset after connect - get command on stopped db taking ~5min to respond with exception

Open andrewtijana opened this issue 1 year ago • 0 comments

Description

We are doing some disaster recovery testing and have stopped our db in order to make sure the node server can respond with a valid error page to the front end. When we stop the db, it takes about 5min for the server to get back a response from redis. I suspect that the socket timeout is not being reset to 0 because of the 5min delay in response. I have tried a bunch of configurations including disabling the offline queue, changing the keepAlive, changing the connect timeout, etc. Nothing seems to change this behaviour.

I've replicated this using the simple client code below.

const { createClient } = require('redis');
const redisOpts = {
    socket: {
        host: '*****',
        port: ****
    },
    username: '****',
    password: '****',
    disableOfflineQueue: true
}

async function run() {
    const client = createClient(redisOpts);

    client.on('error', err => console.log('Redis Client Error', err));
    client.on('ready', () => {
        console.log('connected')
    });
    try {
        await client.connect();
    } catch (e) {
        console.log('failed to connect', e);
    }

    let counter = 0;
    console.log('setting value');
    try {
        await client.set('testkey', counter);
    } catch (e) {
        console.log('failed to set', e);
    }
    let value;
    try {
        value = await client.get('key');
    } catch (e) {
        console.log('failed to get', e);
    }
    console.log(`value ${value}`);
    await client.disconnect();
}
run();

Node.js Version

18.18.1

Redis Server Version

redis_version:6.2.10

Node Redis Version

4.6.8

Platform

Linux

Logs

No response

andrewtijana avatar Dec 04 '23 21:12 andrewtijana