Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

fix: support concurrent access in system report endpoint #3

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

vladklokun
Copy link
Contributor

What this PR changes?

Previously, concurrent access to the global system report endpoint variable resulted in a data race and triggered the race detector.

This commit makes the variable safe for concurrent use.

@vladklokun
Copy link
Contributor Author

TODO: make a Github tag so the new version is available in the Go package registry.

Previously, concurrent access to the global system report endpoint
variable resulted in a data race and triggered the race detector.

This commit makes the variable safe for concurrent use.

Signed-off-by: Vlad Klokun <vklokun@protonmail.ch>
Comment on lines 65 to 81
// SetSystemReportEndpoint sets the system report endpoint to the provided
// value or a default
//
// Deprecated: the SetSysetmReportEndpoint shouldn’t be the setter for an
// unexported variable. Use the sysEndpoint.SetOrDefault() method instead.
func SetSystemReportEndpoint(endpoint string) {
systemReportEndpoint.SetOrDefault(endpoint)
}

// GetSystemReportEndpoint gets the system report endpoint or sets a default
// and returns it
//
// Deprecated: the GetSysetmReportEndpoint shouldn’t be the setter for an
// unexported variable. Use the sysEndpoint.GetOrDefault() method instead.
func GetSystemReportEndpoint() string {
if systemReportEndpoint == "" {
SetSystemReportEndpoint("")
}
return systemReportEndpoint
return systemReportEndpoint.GetOrDefault()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: can we safely remove these functions?

I have only seen these functions being used inside of the armosec/logger-go package. But seeing how these are exported functions, do we expect clients of armosec/logger-go to use it?

If not, then I would like to remove the functions and also make sure that the new concurrent system report endpoint is unexported, private to the logger package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do what ever you think, but there is no reason to waist here time

Signed-off-by: Vlad Klokun <vklokun@protonmail.ch>
@vladklokun vladklokun merged commit dd11a23 into master Aug 23, 2023
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants