Skip to content

Abort scenario still requires waiting for release #309

Description

@ikonst

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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