-
Notifications
You must be signed in to change notification settings - Fork 10
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
Logger goroutine-safety: fatal error: concurrent map writes
#126
Comments
Hey @ewbankkit 👋 Thank you for reporting this and sorry you are running into trouble here. I think the quick version of this issue is that It looks like the calling code here may be trying to log API requests from the provider. There are a few options I can think of here which should alleviate the immediate issue:
func F1(ctx context.Context) {
reqCtx := tflog.SetField(ctx, /*...*/)
reqCtx = tflog.SetField(reqCtx, /*...*/)
tflog.Trace(reqCtx, /*...*/)
F2(reqCtx)
}
func xxx(ctx context.Context, /*...*/) {
fields := map[string]any{/*...*/}
tflog.Trace(ctx, "...", fields)
} One definite action item on our side is to ensure this "shared variable" analogy is well documented in the Fields section. Another would be whether to consider this particular Go panic as something we should actually fix in this codebase. It would be technically possible to prevent the We could introduce logic that checks to see if the I think if I had my preference in this situation, it would be a combination of checking the field, (WARN?) logging on overwrite, implementing Please reach out if you have any questions. |
Reference: #126 Reference: #131 Since the `LoggerOpts` struct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a new `context.Context` without worrying about shared data. This change introduces a `Copy()` method for `LoggerOpts` and implements it for option modifier functions which adjust a map or slice.
Reference: #126 Reference: #131 Since the `LoggerOpts` struct contains slice and map fields, it is important to ensure any modifications occur on copies of those slices and maps, otherwise the memory reference can wind up being shared. Consumers should always be able to create a new `context.Context` without worrying about shared data. This change introduces a `Copy()` method for `LoggerOpts` and implements it for option modifier functions which adjust a map or slice.
After thinking about this more, I believe this issue should be resolved by #132 without additional changes or needing additional documentation. That change should prevent concurrent map writes since each new |
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. |
terraform-plugin-log version
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
(viaaws-sdk-go-base
) to log AWS SDK for Go requests and responses.Under heavy usage we are seeing crashes:
terraform-plugin-log/internal/logging/options.go
Lines 205 to 215 in 2a7a4a8
terraform-plugin-log/tflog/provider.go
Lines 15 to 21 in 2a7a4a8
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.
The text was updated successfully, but these errors were encountered: