Error Acquiring Lock in Redlock: Exceeded Attempts to Lock Resource (Node.js, Typescript)

434 Views Asked by At

I am currently facing an issue while trying to acquire a lock on a key using Redlock. The error message I am encountering is as follows:

Error acquiring lock: LockError: Exceeded X attempts to lock the resource "xxx".

I have already looked into the ongoing issue on GitHub (#168), but none of the suggested solutions seem to be working for me. I have also tried downgrading the versions of ioredis and redlock, but it didn’t help.

Environment: Node.js version: (18.16.0)
Redlock version: (4.2.0)
ioredis version: (5.3.2)

Code snippet:

import Redlock from "redlock";
import { RedlockPort } from "../../../use-case/port/redlock_port.js";
import { Redis } from "ioredis";

export class RedlockAdapter implements RedlockPort {
  private redlock: Redlock;

  constructor(client: Redis) {
    this.redlock = new Redlock([client], { retryCount: 10, retryDelay: 1000 });
   }

  async acquireLock(resource: string) {
    try {
      const lock = await this.redlock.acquire([resource], 1000)
      return lock;
    } catch (e) {
      console.error('Error acquiring lock:', e);
      throw e;
    }
  }

  async releaseLock(lock: Redlock.Lock): Promise<void> {
    await lock.release();
  }
}

Things I've Tried:
Downgrading ioredis and redlock to previous versions.

Has anyone encountered a similar issue or does anyone know a workaround for this problem? Any suggestions or advice would be highly appreciated.

Downgrading ioredis and redlock to previous versions and it didn't help. Tried logging the client to see if its there and it is. Tried setting other configs for redlock and it didn't help.

0

There are 0 best solutions below