Skip to content

createClient not work after quit #63

@dontbesatisfied

Description

@dontbesatisfied

Node: v12.18.2
redis: 5.0.5 (docker image)
async-redis: 2.0.0

Error occur as " AbortError: BLPOP can't be processed. The connection is already closed. "

This is ample code where an error occurs.

const redis = require('async-redis')

let client = redis.createClient("redis://localhost:6379");

let cnt = 0;

async function reconnect() {
    try {
        await client.quit()
        client = null
        client = redis.createClient("redis://localhost:6379");
        console.log('reconnect');
    } catch (error) {
        console.log(error);
    }
}


(async () => {
    while (true) {
        try {
            
            cnt++

            const v = await client.blpop('*', 1)

            if (cnt%5 === 0) {
                throw Error("Test")
            }
        } catch (error) {
            console.error(error);
            await reconnect()
            
        }
    }
})()

But below code work well.
There seems to be a problem with clients with the same option as they connected before.

is it bug?

const redis = require('async-redis')

let client = redis.createClient("redis://localhost:6379");

let cnt = 0;

async function reconnect() {
    try {
        await client.quit()
        client = null
        client = redis.createClient("redis://localhost:6379", {
            customOption: Date.now(), // Here
        });
        console.log('reconnect');
    } catch (error) {
        console.log(error);
    }
}


(async () => {
    while (true) {
        try {
            
            cnt++

            const v = await client.blpop('*', 1)

            if (cnt%5 === 0) {
                throw Error("Test")
            }
        } catch (error) {
            console.error(error);
            await reconnect()
            
        }
    }
})()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions