Skip to content

Commit

Permalink
🧵 add mutex when running provider.connect()
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Dec 12, 2024
1 parent 17f7beb commit 842e1e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ test: test/go test/lint
benchmark/go:
go test -bench=. -benchmem go.mondoo.com/cnquery/v11/explorer/scan/benchmark

race/go:
go test -race go.mondoo.com/cnquery/v11/internal/workerpool
go test -race go.mondoo.com/cnquery/v11/explorer/scan

test/generate: prep/tools/mockgen
go generate ./providers

Expand Down
5 changes: 5 additions & 0 deletions providers/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type Runtime struct {
isClosed bool
close sync.Once
shutdownTimeout time.Duration

// used to lock unsafe tasks
mu sync.Mutex
}

type ConnectedProvider struct {
Expand Down Expand Up @@ -232,7 +235,9 @@ func (r *Runtime) Connect(req *plugin.ConnectReq) error {

// }

r.mu.Lock()
r.Provider.Connection, r.Provider.ConnectionError = r.Provider.Instance.Plugin.Connect(req, &callbacks)
r.mu.Unlock()
if r.Provider.ConnectionError != nil {
return r.Provider.ConnectionError
}
Expand Down

0 comments on commit 842e1e7

Please sign in to comment.