Skip to content

Logger goroutine-safety: fatal error: concurrent map writes #126

@ewbankkit

Description

@ewbankkit

terraform-plugin-log version

% go list -m github.com/hashicorp/terraform-plugin-log/...
github.com/hashicorp/terraform-plugin-log v0.7.0

Relates hashicorp/terraform-provider-aws#29236.

With v4.53.0, released 02/02/2023, the Terraform AWS Provider has started to use terraform-plugin-log (via aws-sdk-go-base) to log AWS SDK for Go requests and responses.
Under heavy usage we are seeing crashes:

fatal error: concurrent map writes
goroutine 1730 [running]:
github.com/hashicorp/terraform-plugin-log/tflog.SetField.func1(...)
	github.com/hashicorp/[email protected]/internal/logging/options.go:212
github.com/hashicorp/terraform-plugin-log/tflog.SetField({0xe25bd00, 0xc001d5f890}, {0xce4900e, 0xb}, {0xa619820?, 0xc00089eb90})
	github.com/hashicorp/[email protected]/tflog/provider.go:18 +0x111
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2.setAWSFields({0xe25bd00?, 0xc003bc12f0?}, 0xc005cbaa00)
	github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/[email protected]/logger.go:40 +0x9c
github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2.logRequest(0xc005cbaa00)
	github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/[email protected]/logger.go:69 +0x5f
...

func WithField(key string, value interface{}) Option {
return func(l LoggerOpts) LoggerOpts {
// Lazily create this map, on first assignment
if l.Fields == nil {
l.Fields = make(map[string]interface{})
}
l.Fields[key] = value
return l
}
}

func SetField(ctx context.Context, key string, value interface{}) context.Context {
lOpts := logging.GetProviderRootTFLoggerOpts(ctx)
lOpts = logging.WithField(key, value)(lOpts)
return logging.SetProviderRootTFLoggerOpts(ctx, lOpts)
}

https://github.com/hashicorp/aws-sdk-go-base/blob/f0b32e1671652e7f19ebd715676fceb7c37190f2/v2/awsv1shim/logger.go#L38-L51

It is not clear which component is responsible for ensuring goroutine-safety here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions