Skip to content

fix(coderd/cryptokeys): relock mutex to avoid double unlock #16802

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

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Mar 4, 2025

@mafredri mafredri requested review from spikecurtis and sreya and removed request for spikecurtis March 4, 2025 16:16
@@ -255,6 +255,7 @@ func (c *cache) cryptoKey(ctx context.Context, sequence int32) (string, []byte,

keys, err := c.cryptoKeys(ctx)
if err != nil {
c.mu.Lock() // Re-lock because of defer.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's clearer to move the Lock call from L262 up like:

c.mu.Unlock()
keys, err := c.cryptoKeys(ctx)
c.mu.Lock()
if err != nil {
    return "", nil, xerrors.Errorf("get keys: %w", err)
}

That way it's clear that we are unlocking just for the c.cryptoKeys() call.

@mafredri mafredri enabled auto-merge (squash) March 4, 2025 17:00
@mafredri mafredri merged commit 6dd71b1 into main Mar 4, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/fix-coderd-cryptokeys-unlock branch March 4, 2025 17:10
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants