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: Use locking when creating new keypairs #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

koesie10
Copy link
Contributor

@koesie10 koesie10 commented Mar 7, 2022

This adds an advisory lock when creating a new keypair to prevent
creating multiple keypairs for the same validity period.

Closes #10

This adds an advisory lock when creating a new keypair to prevent
creating multiple keypairs for the same validity period.

References #10
LOCK_NAME = 'keypairs:rotate'

def rotate_keys_with_lock!
with_advisory_lock(LOCK_NAME) do
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, Isn't this a bit overkill? How does this relate with the pessimistic locking like https://api.rubyonrails.org/classes/ActiveRecord/Locking/Pessimistic.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you that a solution like pessimistic or optimistic locking would be easier. However, we don't always have a clear idea which record to use for locking. For example, when we don't have any keypairs yet we don't have any records which we can lock. It's also not clear on which record we should lock, especially when there are multiple keypairs for the same time period, as there would be when migrating from a previous version of the gem.

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.

Race condition when creating new keypairs
2 participants