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

helper/schema: Crash while updating set in MapFieldWriter.setSet #14418

Closed
kpettijohn opened this issue May 11, 2017 · 5 comments · Fixed by #20891
Closed

helper/schema: Crash while updating set in MapFieldWriter.setSet #14418

kpettijohn opened this issue May 11, 2017 · 5 comments · Fixed by #20891
Milestone

Comments

@kpettijohn
Copy link

Terraform Version

terraform --version
Terraform v0.9.5

Affected Resource(s)

Overall it seems to happen across multiple resources but aws_launch_configuration is always included with unexpected EOF, while other resources will have a connection is shut down or the unexpected EOF error.

  • aws_launch_configuration
  • aws_autoscaling_group

Terraform Configuration Files

I will need to scrub the configuration files before posting.

Debug Output

I will need to scrub the debug output before posting.

Panic Output

https://gist.github.com/kpettijohn/82eef460a4cdf094efce08100fbba5d0

Expected Behavior

Successful plan

Actual Behavior

Crash

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan or terraform apply

Terraform will crash roughly 50-75% of the time when executing a plan or apply.

@atbentley
Copy link

I was also having the unexpected EOF issue on 0.9.5. I was running terraform inside a docker container with a CPU shares limit imposed on it. I was able to stop terraform from crashing by increasing the amount of CPU resources available to the docker container.

@apparentlymart
Copy link
Contributor

apparentlymart commented May 31, 2017

Here is the stack trace from the panic output, for easier reference:

panic: set item just set doesn't exist
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5:
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: goroutine 552 [running]:
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).setSet(0xc421e43d80, 0xc421de72a0, 0x1, 0x1, 0x4f8de40, 0xc421ed85a0, 0xc421602780, 0x0, 0x1)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:302 +0x938
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).set(0xc421e43d80, 0xc421de72a0, 0x1, 0x1, 0x4f8de40, 0xc421ed8480, 0x1, 0x0)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:94 +0x364
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).WriteField(0xc421e43d80, 0xc421de72a0, 0x1, 0x1, 0x4f8de40, 0xc421ed8480, 0x0, 0x0)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:76 +0x18c
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*ResourceData).Set(0xc420232310, 0x5d46bca, 0x11, 0x4f8de40, 0xc421ed8480, 0x0, 0x0)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/resource_data.go:171 +0x143
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/builtin/providers/aws.readLCBlockDevices(0xc420232310, 0xc421af2270, 0xc421a8c380, 0x4f6b900, 0xc421e44040)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/resource_aws_launch_configuration.go:593 +0x281
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/builtin/providers/aws.resourceAwsLaunchConfigurationRead(0xc420232310, 0x55ce500, 0xc4203d0000, 0x0, 0x8777080)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/builtin/providers/aws/resource_aws_launch_configuration.go:552 +0x7bf
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*Resource).Refresh(0xc4215fe000, 0xc421a2fcc0, 0x55ce500, 0xc4203d0000, 0xc4216743c8, 0xc422366101, 0xc4202ac000)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/resource.go:314 +0x21d
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/helper/schema.(*Provider).Refresh(0xc42065d180, 0xc421a2fc70, 0xc421a2fcc0, 0x9b284b0, 0x0, 0x5004a00)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/helper/schema/provider.go:267 +0x91
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: github.com/hashicorp/terraform/plugin.(*ResourceProviderServer).Refresh(0xc4215a4260, 0xc4213d0ee0, 0xc4213d14b0, 0x0, 0x0)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/gopath/src/github.com/hashicorp/terraform/plugin/resource_provider.go:510 +0x4e
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: reflect.Value.call(0xc4207b52c0, 0xc42121ab40, 0x13, 0x5d0d1f4, 0x4, 0xc421b73f20, 0x3, 0x3, 0xe, 0x0, ...)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/go/src/reflect/value.go:434 +0x91f
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: reflect.Value.Call(0xc4207b52c0, 0xc42121ab40, 0x13, 0xc421992f20, 0x3, 0x3, 0x11cb0d0, 0x86e4740, 0xc421a104e0)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/go/src/reflect/value.go:302 +0xa4
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: net/rpc.(*service).call(0xc42154e2c0, 0xc42154e280, 0xc421591300, 0xc421550b00, 0xc4215a42e0, 0x4e841e0, 0xc4213d0ee0, 0x16, 0x4e84220, 0xc4213d14b0, ...)
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/go/src/net/rpc/server.go:387 +0x144
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: created by net/rpc.(*Server).ServeCodec
2017/05/11 14:35:49 [DEBUG] plugin: terraform_v0_9_5: 	/opt/go/src/net/rpc/server.go:481 +0x404

@apparentlymart apparentlymart changed the title AWS provider unexpected EOF provider/aws: crash while updating set in aws_launch_configuration May 31, 2017
@duckalini
Copy link

I'm also seeing this, with v0.9.6.

@radeksimko radeksimko changed the title provider/aws: crash while updating set in aws_launch_configuration helper/schema: Crash while updating set in MapFieldWriter.setSet Aug 4, 2017
bflad added a commit that referenced this issue Apr 2, 2019
References:

* #14418
* v0.9.5 (original bug report): https://github.com/hashicorp/terraform/blob/a59ee0b30e1350d18e44a3a2a405124302751f93/helper/schema/field_writer_map.go#L311
* v0.11.12 (Terraform AWS Provider discovery): https://github.com/hashicorp/terraform/blob/057286e5228559722bfc9bf6a03679650358c9d2/helper/schema/field_writer_map.go#L343

When creating flatten functions in Terraform Providers that return *schema.Set, its possible to return a typed `nil`, e.g.

```go
func flattenHeaders(h *cloudfront.Headers) *schema.Set {
	if h.Items != nil {
		return schema.NewSet(schema.HashString, flattenStringList(h.Items))
	}
	return nil
}
```

This previously could cause a panic, e.g.

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1881911]

goroutine 1325 [running]:
github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).setSet(0xc00054bf00, 0xc00073efa0, 0x5, 0x5, 0x5828140, 0x0, 0xc0002cea50, 0xc000e996a8, 0xc001026e40)
	/Users/bflad/go/pkg/mod/github.com/hashicorp/[email protected]/helper/schema/field_writer_map.go:343 +0x211
```

Here we catch the typed `nil` and return an empty list flatmap result instead. Unit testing result prior to code update:

```
--- FAIL: TestMapFieldWriter (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
  panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1777cdc]

goroutine 913 [running]:
testing.tRunner.func1(0xc00045b800)
  /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:830 +0x392
panic(0x192cf20, 0x2267ca0)
  /usr/local/Cellar/go/1.12.1/libexec/src/runtime/panic.go:522 +0x1b5
github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).setSet(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0xc00045c600, 0x30, 0x19e0080)
  /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:344 +0x68c
github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).set(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0x1, 0x18)
  /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:107 +0x28b
github.com/hashicorp/terraform/helper/schema.(*MapFieldWriter).WriteField(0xc0004648a0, 0xc0004408d0, 0x1, 0x1, 0x19e3de0, 0x0, 0x0, 0x0)
  /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map.go:89 +0x504
github.com/hashicorp/terraform/helper/schema.TestMapFieldWriter(0xc00045b800)
  /Users/bflad/src/github.com/hashicorp/terraform/helper/schema/field_writer_map_test.go:337 +0x2ddd
testing.tRunner(0xc00045b800, 0x1a44f90)
  /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
  /usr/local/Cellar/go/1.12.1/libexec/src/testing/testing.go:916 +0x35a
```
@bflad bflad added this to the v0.12.0 milestone Apr 3, 2019
@bflad
Copy link
Contributor

bflad commented Apr 3, 2019

The panic prevention fix for the Terraform Provider SDK has been merged and will release with version 0.12.0-beta2 of Terraform in the coming weeks. Terraform Providers will need to update their Terraform Provider SDK dependency to receive this fix. The new behavior is setting an empty list into the Terraform state when attempting to write a typed nil of *schema.Set for TypeSet attributes.

@ghost
Copy link

ghost commented Aug 13, 2019

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 and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants