race condition when same `*http.Client` is used in the asrockrack and redfish providers
jacobweinstock opened this issue · 1 comments
jacobweinstock commented
To reproduce: Run go test -timeout 30s -run ^TestBMC$ github.com/bmc-toolbox/bmclib/v2 -race
(comment out the t.Skip
). In this file, the race happens when cl.FilterForCompatible(ctx)
is called.
One option is to copy the *http.Client
and pass the copy to the redfish provider.
// register ASRR vendorapi provider
driverAsrockrack, _ := asrockrack.NewWithOptions(c.Auth.Host, c.Auth.User, c.Auth.Pass, c.Logger, asrockrack.WithHTTPClient(c.httpClient))
c.Registry.Register(asrockrack.ProviderName, asrockrack.ProviderProtocol, asrockrack.Features, nil, driverAsrockrack)
// register gofish provider
httpClient := *c.httpClient
driverGoFish := redfish.New(c.Auth.Host, c.Auth.Port, c.Auth.User, c.Auth.Pass, c.Logger, redfishwrapper.WithHTTPClient(&httpClient), redfishwrapper.WithVersionsNotCompatible(c.redfishVersionsNotCompatible))
c.Registry.Register(redfish.ProviderName, redfish.ProviderProtocol, redfish.Features, nil, driverGoFish)
==================
WARNING: DATA RACE
Read at 0x00c0000a1318 by goroutine 9:
net/http.(*Client).deadline()
/usr/local/go/src/net/http/client.go:189 +0x3e
net/http.(*Client).do()
/usr/local/go/src/net/http/client.go:600 +0x117
net/http.(*Client).Do()
/usr/local/go/src/net/http/client.go:582 +0x951
github.com/bmc-toolbox/bmclib/v2/providers/asrockrack.(*ASRockRack).queryHTTPS()
/bmclib/providers/asrockrack/helpers.go:592 +0x925
github.com/bmc-toolbox/bmclib/v2/providers/asrockrack.(*ASRockRack).Compatible()
/bmclib/providers/asrockrack/asrockrack.go:100 +0x74
github.com/jacobweinstock/registrar.Registry.FilterForCompatible.func1()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:106 +0x28e
github.com/jacobweinstock/registrar.Registry.FilterForCompatible.func2()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:118 +0x74
Previous write at 0x00c0000a1318 by goroutine 10:
github.com/bmc-toolbox/bmclib/v2/internal/redfishwrapper.(*Client).Open()
/bmclib/internal/redfishwrapper/client.go:107 +0x24c
github.com/bmc-toolbox/bmclib/v2/providers/redfish.(*Conn).Open()
/bmclib/providers/redfish/redfish.go:58 +0x84
github.com/bmc-toolbox/bmclib/v2/providers/redfish.(*Conn).Compatible()
/bmclib/providers/redfish/redfish.go:73 +0x5d
github.com/jacobweinstock/registrar.Registry.FilterForCompatible.func1()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:106 +0x28e
github.com/jacobweinstock/registrar.Registry.FilterForCompatible.func2()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:118 +0x74
Goroutine 9 (running) created at:
github.com/jacobweinstock/registrar.Registry.FilterForCompatible()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:103 +0x464
github.com/bmc-toolbox/bmclib/v2.(*Client).FilterForCompatible()
/repos/bmc/bmclib/client.go:237 +0x178
github.com/bmc-toolbox/bmclib/v2.TestBMC()
/repos/bmc/bmclib/client_test.go:24 +0x1d0
testing.tRunner()
/usr/local/go/src/testing/testing.go:1576 +0x216
testing.(*T).Run.func1()
/usr/local/go/src/testing/testing.go:1629 +0x47
Goroutine 10 (running) created at:
github.com/jacobweinstock/registrar.Registry.FilterForCompatible()
/go/pkg/mod/github.com/jacobweinstock/registrar@v0.4.6/registrar.go:103 +0x464
github.com/bmc-toolbox/bmclib/v2.(*Client).FilterForCompatible()
/bmclib/client.go:237 +0x178
github.com/bmc-toolbox/bmclib/v2.TestBMC()
/bmclib/client_test.go:24 +0x1d0
testing.tRunner()
/usr/local/go/src/testing/testing.go:1576 +0x216
testing.(*T).Run.func1()
/usr/local/go/src/testing/testing.go:1629 +0x47
==================
--- FAIL: TestBMC (5.00s)
/bmclib/client_test.go:28: 1 error occurred:
* no Opener implementations found
/bmclib/testing.go:1446: race detected during execution of test
jacobweinstock commented
Fixed in #325