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

SEGV when DNS resolver misconfigured #23015

Open
mouchar opened this issue Oct 7, 2019 · 1 comment
Open

SEGV when DNS resolver misconfigured #23015

mouchar opened this issue Oct 7, 2019 · 1 comment
Labels
backend/remote bug crash v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@mouchar
Copy link

mouchar commented Oct 7, 2019

When DNS resolver is misconfigured (it happened to me in Docker container after suspending laptop and resuming in other network), the terraform plan command fails on SIGSEGV. I'm using remote backend on app.terraform.io.
Hopefully, terraform workspace list handles error correctly with a reasonable error message Error: Failed to request discovery document: Get https://app.terraform.io/.well-known/terraform.json: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

Terraform Version

Terraform v0.12.9
+ provider.aws v2.31.0

Terraform Configuration Files

Not relevant for this issue

Debug Output

Pasting debug output here since it's very short (TF fails soon):

TF_LOG=TRACE terraform apply /tmp/plan
2019/10/07 10:27:18 [INFO] Terraform version: 0.12.9  
2019/10/07 10:27:18 [INFO] Go runtime version: go1.12.9
2019/10/07 10:27:18 [INFO] CLI args: []string{"/bin/terraform", "apply", "/tmp/plan"}
2019/10/07 10:27:18 [DEBUG] Attempting to open CLI config file: /root/credentials.tf
2019/10/07 10:27:18 Loading CLI configuration from /root/credentials.tf
2019/10/07 10:27:18 [INFO] CLI command args: []string{"apply", "/tmp/plan"}
2019/10/07 10:27:18 [TRACE] Meta.BackendForPlan: instantiated backend of type *remote.Remote
2019/10/07 10:27:18 [DEBUG] Service discovery for app.terraform.io at https://app.terraform.io/.well-known/terraform.json
2019/10/07 10:27:29 [DEBUG] checking for provider in "."
2019/10/07 10:27:29 [DEBUG] checking for provider in "/bin"
2019/10/07 10:27:29 [DEBUG] checking for provider in ".terraform/plugins/linux_amd64"
2019/10/07 10:27:29 [DEBUG] found provider "terraform-provider-aws_v2.31.0_x4"
2019/10/07 10:27:29 [DEBUG] found valid plugin: "aws", "2.31.0", "/root/aws/.terraform/plugins/linux_amd64/terraform-provider-aws_v2.31.0_x4"
2019/10/07 10:27:29 [DEBUG] checking for provisioner in "."
2019/10/07 10:27:29 [DEBUG] checking for provisioner in "/bin"
2019/10/07 10:27:29 [DEBUG] checking for provisioner in ".terraform/plugins/linux_amd64"
2019/10/07 10:27:29 [TRACE] Meta.BackendForPlan: backend *remote.Remote supports operations

Crash Output

see crash.log

Expected Behavior

A self-explanatory error message like Cannot resolve host app.terraform.io: Network timeout or so.

Actual Behavior

SIGSEGV crash

Steps to Reproduce

  1. have an existing workspace with a remote backend
  2. change DNS server in /etc/resolv.conf to an unreachable address
  3. run terraform apply

Additional Context

N/A

References

N/A

@hashibot hashibot added backend/remote bug v0.12 Issues (primarily bugs) reported against v0.12 releases crash labels Oct 7, 2019
@remil1000
Copy link

looks like some error checking on the Configure stage isn't well handled in command/meta_backend.go, func BackendForPlan

I've tried the following patch, seems to work

diff --git a/command/meta_backend.go b/command/meta_backend.go
index c62be4630..ad51ef681 100644
--- a/command/meta_backend.go
+++ b/command/meta_backend.go
@@ -246,6 +246,9 @@ func (m *Meta) BackendForPlan(settings plans.Backend) (backend.Enhanced, tfdiags
 
        configureDiags := b.Configure(newVal)
        diags = diags.Append(configureDiags)
+       if configureDiags.HasErrors() {
+               return nil, diags
+       }
 
        // If the backend supports CLI initialization, do it.
        if cli, ok := b.(backend.CLI); ok {

now I get a proper message when applying from plan file

$  terraform apply tfplan

Error: Failed to request discovery document: Get https://app.terraform.io/.well-known/terraform.json: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend/remote bug crash v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

3 participants