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

fix: Eliminate data race in modules integration #105

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
// Modules Integration
// ================================

type modulesIntegration struct{}

var _modulesCache map[string]string // nolint: gochecknoglobals
var _modulesCached bool // nolint: gochecknoglobals
type modulesIntegration struct {
once sync.Once
modules map[string]string
}

func (mi *modulesIntegration) Name() string {
return "Modules"
Expand All @@ -31,26 +31,20 @@ func (mi *modulesIntegration) SetupOnce(client *Client) {

func (mi *modulesIntegration) processor(event *Event, hint *EventHint) *Event {
if len(event.Modules) == 0 {
event.Modules = extractModules()
mi.once.Do(func() {
mi.modules = extractModules()
})
}

event.Modules = mi.modules
return event
}

func extractModules() map[string]string {
if _modulesCached {
return _modulesCache
}

_modulesCached = true
extractedModules, err := getModules()
if err != nil {
Logger.Printf("ModuleIntegration wasn't able to extract modules: %v\n", err)
return nil
}

_modulesCache = extractedModules

return extractedModules
}

Expand Down