Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug lazyConnect does not allow multiple connect() calls #1192

Open
pomgui opened this issue Jul 6, 2022 · 0 comments
Open

Bug lazyConnect does not allow multiple connect() calls #1192

pomgui opened this issue Jul 6, 2022 · 0 comments
Labels

Comments

@pomgui
Copy link

pomgui commented Jul 6, 2022

When a client is created using lazyConnect, then a connect() is required and it works fine.
However, when a disconnect() is called, a new connect() is not allowed anymore.

Let's consider the following example:

const Redis = require('ioredis-mock');

console.log('Creating client...');
const client = new Redis('redis://localhost:6379', { lazyConnect: true });
console.log(`client.connected: ${client.connected}`);
let attempt = 1;

session()
.then(session)
.catch(e => console.error(e));

async function session() {
    console.log('\nAttempt #' + attempt++);
    console.log('connecting...');
    await client.connect();
    console.log(`After connect(): client.connected: ${client.connected}`);
    console.log('disconnecting...');
    await client.disconnect();
    console.log(`After disconnect(): client.connected: ${client.connected}`);
}

The output is:

Creating client...
client.connected: false

Attempt #1
connecting...
After connect(): client.connected: true
disconnecting...
After disconnect(): client.connected: true

Attempt #2
connecting...
Error: Redis is already connecting/connected
    at RedisMock.connect (/tmp/ioredis/node_modules/ioredis-mock/lib/index.js:2220:11)
    at safelyExecuteCommand (/tmp/ioredis/node_modules/ioredis-mock/lib/index.js:1713:16)
    at /tmp/ioredis/node_modules/ioredis-mock/lib/index.js:1721:192
    at new Promise (<anonymous>)
    at RedisMock.connect (/tmp/ioredis/node_modules/ioredis-mock/lib/index.js:1721:159)
    at session (/tmp/ioredis/test.js:16:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Solution

Perhaps I'm being too simplistic, but it seems the solution is updating the connected property to false on the disconnect() method.

@stipsan stipsan added the bug label Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants