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

Abort scenario still requires waiting for release #309

Open
ikonst opened this issue Oct 4, 2024 · 3 comments
Open

Abort scenario still requires waiting for release #309

ikonst opened this issue Oct 4, 2024 · 3 comments

Comments

@ikonst
Copy link

ikonst commented Oct 4, 2024

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
Copy link
Author

ikonst commented Oct 4, 2024

Appears to be addressed in babelcloud#1

@vitalyiegorov
Copy link

@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
Copy link
Author

ikonst commented Oct 27, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants