mike-marcacci / node-redlock

A node.js redlock implementation for distributed, highly-available redis locks
MIT License
1.84k stars 172 forks source link

Abort scenario still requires waiting for release #309

Open ikonst opened 1 month ago

ikonst commented 1 month ago

When the 'aborted' signal is given, am I right to assume there's some certainty about the lock no longer being valid?

Currently Redlock.using will spend time trying to release the lock, eventually failing with "The operation was unable to achieve a quorum during its retry window", e.g.

function blockEventLoop(ms) {
  for (const start = Date.now(); Date.now() - start < ms; ) {}
}

async function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

async function test() {
  console.time("lock");
  try {
    const lock = await redlock.using(
      [id],
      200,
      {
        automaticExtensionThreshold: 100,
      },
      async (abortSignal) => {
        blockEventLoop(200); // prevent auto-extend
        await sleep(200); // allow auto-extend to be attempted
        if (abortSignal.aborted) {
          console.log('aborted');
          throw abortSignal.error;
        }
      },
    );
  } except (err) {
    console.log(err);
  } finally {
    console.timeEnd("lock"); // will print between 2000ms and 3000ms (per jitter)
  }
}

void test();

will print

aborted
The operation was unable to achieve a quorum during its retry window
lock: 2500 ms
ikonst commented 1 month ago

Appears to be addressed in https://github.com/babelcloud/node-redlock/pull/1

vitalyiegorov commented 3 weeks ago

@royvandewater @slosd @veeti @tobico Is this package not maintained anymore? It has a significant amount of weekly downloads almost 600k, https://www.npmjs.com/package/redlock maybe we can revive it? Seems like CI is not working anymore and noone is working on that

ikonst commented 3 weeks ago

@vitalyiegorov You can fork it, and many have. For instance, you can see the changes we've adopted in my company: https://github.com/rutter/node-redlock