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

TFC local execution doesn't seem to respect the -lock-timeout option #27844

Closed
chapmanc opened this issue Feb 19, 2021 · 3 comments · Fixed by #27845
Closed

TFC local execution doesn't seem to respect the -lock-timeout option #27844

chapmanc opened this issue Feb 19, 2021 · 3 comments · Fixed by #27845
Assignees
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.14 Issues (primarily bugs) reported against v0.14 releases v0.15 Issues (primarily bugs) reported against v0.15 releases

Comments

@chapmanc
Copy link

Terraform Version

Terraform v0.12.29

 terraform -v
Terraform v0.12.29
+ provider.null v3.1.0
+ provider.time v0.7.0

Your version of Terraform is out of date! The latest version
is 0.14.7. You can update by downloading from https://www.terraform.io/downloads.html

Terraform v0.14.7

Terraform v0.14.7
+ provider registry.terraform.io/hashicorp/null v3.1.0
+ provider registry.terraform.io/hashicorp/time v0.7.0

Terraform Configuration Files

terraform {
  backend "remote" {
    organization = "chappie"

    workspaces {
      name = "testing"
    }
  }
}
resource "null_resource" "previous" {}

resource "time_sleep" "wait_100s" {
  depends_on = [null_resource.previous]

  create_duration = "100s"
}

# This resource will create (at least) 100 seconds after null_resource.previous
resource "null_resource" "next" {
  depends_on = [time_sleep.wait_100s]
}

Debug Output

This is difficult to show as it is a result of multiple runs.

Crash Output

N/A

Expected Behavior

When specifying -lock-timeout=120s terraform plans should hang until the specified timeout has completed and then fail with a lock error.

Error: Error locking state: Error acquiring the state lock: workspace already locked (lock ID: "chappie/testing")

Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.

Actual Behavior

When specifying -lock-timeout=120s terraform plans immediately fail with a lock error.

Steps to Reproduce

  1. terraform login
  2. terraform init
  3. After running for i in {1..10}; do terraform plan -lock=true -lock-timeout=120s & done I would expect that it would fail after 120s due to the lock timeout with ~ 1-2 plans succeeding. Instead 1 plan begins and all the other plans fail due to:
Error: Error locking state: Error acquiring the state lock: workspace already locked (lock ID: "chappie/testing")

Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.

Additional Context

References

@alisdair

@chapmanc chapmanc added bug new new issue not yet triaged labels Feb 19, 2021
@alisdair
Copy link
Contributor

Thanks for reporting this! I'm able to reproduce it on Terraform 0.14 and the current main branch.

Note for repro steps:

  • Local operations on the workspace is essential
  • Try starting one apply and then a plan while the apply is running

This doesn't seem to affect all locking backends (I tested Consul, which behaves as you'd expect). Trace logs on the subsequent plan operation show that a lock attempt is made and instantly fails:

2021-02-19T15:00:53.772-0500 [TRACE] backend/local: requesting state lock for workspace "default"
╷
│ Error: Error acquiring the state lock

For anyone picking this up: my best guess here is that the remote backend is either not receiving a clistate.Locker with the correct timeout, or it is failing to pass it to its local backend.

@alisdair alisdair added confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.14 Issues (primarily bugs) reported against v0.14 releases v0.15 Issues (primarily bugs) reported against v0.15 releases and removed new new issue not yet triaged labels Feb 19, 2021
@alisdair
Copy link
Contributor

My guess was wrong, the timeout value is making it to the appropriate places.

The problem is that the remote backend is not populating the Info field of the LockError when locking fails, which prevents lock retry.

@chapmanc chapmanc changed the title TFE local execution doesn't seem to respect the -lock-timeout option TFC local execution doesn't seem to respect the -lock-timeout option Feb 20, 2021
@ghost
Copy link

ghost commented Mar 25, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.14 Issues (primarily bugs) reported against v0.14 releases v0.15 Issues (primarily bugs) reported against v0.15 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants