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

backend/local: Fix lock when applying stale plan #28819

Merged
merged 1 commit into from
May 27, 2021

Conversation

alisdair
Copy link
Contributor

@alisdair alisdair commented May 26, 2021

When returning from the context method, a deferred function call checked for error diagnostics in the diags variable, and unlocked the state if any exist. This means that we need to be extra careful to mutate that variable when returning errors, rather than returning a different set of diags in the same position.

Previously this would result in an invalid plan file causing a lock to become stuck. Fixes #28693.

The defer in question:

defer func() {
// If we're returning with errors, and thus not producing a valid
// context, we'll want to avoid leaving the workspace locked.
if diags.HasErrors() {
diags = diags.Append(op.StateLocker.Unlock())
}
}()

When returning from the context method, a deferred function call checked
for error diagnostics in the `diags` variable, and unlocked the state if
any exist. This means that we need to be extra careful to mutate that
variable when returning errors, rather than returning a different set of
diags in the same position.

Previously this would result in an invalid plan file causing a lock to
become stuck.
@alisdair alisdair requested a review from a team May 26, 2021 20:11
@alisdair alisdair self-assigned this May 26, 2021
@alisdair alisdair added the 0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label May 26, 2021
@alisdair alisdair merged commit 875f4dc into main May 27, 2021
@alisdair alisdair deleted the alisdair/fix-stuck-lock-when-applying-state-plan branch May 27, 2021 13:50
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged backend/local
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trying to apply a stale TF plan does not remove state locks (0.15)
2 participants