Skip to content

fix: Use locking when creating new keypairs - #11

Open
koesie10 wants to merge 1 commit into
mainfrom
issue/10
Open

koesie10 wants to merge 1 commit into
mainfrom
issue/10

Conversation

@koesie10

@koesie10 koesie10 commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

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
Comment thread lib/keypair.rb
LOCK_NAME = 'keypairs:rotate'

def rotate_keys_with_lock!
with_advisory_lock(LOCK_NAME) do

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