Skip to content

Fix race condition when setting mutex key#6

Open
clupprich wants to merge 3 commits intosongkick:masterfrom
clupprich:fix-race-condition
Open

Fix race condition when setting mutex key#6
clupprich wants to merge 3 commits intosongkick:masterfrom
clupprich:fix-race-condition

Conversation

@clupprich
Copy link
Copy Markdown

There's the possibility of a race condition when we're acquiring a new mutex:

DistributedMutex.attempt_to_lock first checks if current_lock is nil and only then sets the mutex key. However, the command that's used there is SET, which

If key already holds a value, it is overwritten[…].

We need to either use SETNX (which is deprecated) or use SET command with the NX option to

Only set the key if it does not already exist.

I'm also setting the expiration time for the key in the same command, as we don't wanna touch that if it already exists.

Had to limit the version of Rake that can be used, as it would error with newer versions.

clupprich and others added 3 commits January 14, 2022 14:50
11.0 introduces a breaking change that removes the `#last_comment` method that rspec < 3 needs.
@clupprich
Copy link
Copy Markdown
Author

Pinging @ericescalante who originally implemented the switch from memcached -> Redis in a58f6ca.

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

Successfully merging this pull request may close these issues.

1 participant