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

Fix extension failure issue #167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ export default class Redlock extends EventEmitter {
throw new Error("Duration must be an integer value in milliseconds.");
}

const start = Date.now();
const value = this._random();

try {
Expand All @@ -313,6 +312,8 @@ export default class Redlock extends EventEmitter {
settings
);

const start = Date.now();
Copy link
Owner

@mike-marcacci mike-marcacci May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You make a very good point here, but I don't think this implementation is safe: the intent is that the expiration on the JS object is either the same or earlier than the one in redis. This change gets the time after it succeeds and calculates an effective expiration that could exceed the actual guarantee.

That said, I completely agree that each new attempt should use a new "start" saved just before making the actual redis calls.

Copy link
Author

@sola92 sola92 May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Happy to close this out in favor of a better solution from your end


// Add 2 milliseconds to the drift to account for Redis expires precision,
// which is 1 ms, plus the configured allowable drift factor.
const drift =
Expand Down