Closed BoskyWSMFN closed 4 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 83.0%. Comparing base (
a88c186
) to head (de49d7b
). Report is 6 commits behind head on main.
Thanks for catching the race. Lock is easy but heavy solution. Please give me time to think about a light alternative.
By the way, could you share your test? I run go test -v -shuffle=on -count=100 -race ./...
under konf and it always succeed on my Mac
Although simple pointer also works since konf allows near latest value but it's annoying since it always fails race test.
378 is an light alternative. I need to add tests on it
Ah, sure. I had an idea to use sync.Map but this solution could broke something related to config or provider structs.
Thanks for catching the race. Lock is easy but heavy solution. Please give me time to think about a light alternative.
Just a brute force solution. Atomic pointer looks way better. I am quite short on time to dig into the code so doing what I can trying not to break something.
then I close this PR and use #378. Would you please take a look at #378? thanks
Thanks for catching the race. Lock is easy but heavy solution. Please give me time to think about a light alternative.
Just a brute force solution. Atomic pointer looks way better. I am quite short on time to dig into the code so doing what I can trying not to break something.
Cool. I just merged the PR. Please let me know if you would like a new release.
go test -v -shuffle=on -count=100 -race
Caught this race in a docker gitlab runner so i can't do it there. No data races on my linux machine though.
Command:
CGO_ENABLED=1 GOARCH=amd64 CC='gcc' CXX='g++' CGO_CFLAGS='-g1 -O2' CGO_CPPFLAGS='' CGO_LDFLAGS='-static-libgcc -static-libstdc++ -static ' go test -timeout 5m -race -short -tags 'netgo' -ldflags '-linkmode external' `go list ./... | grep -v external ` # except external dir
Code where data race appeared:
func (c *configManagement) setOnChangeHook(ctx context.Context) {
c.Konf().OnChange(c.unmarshalConfigsLogError(ctx))
}
func (c *configManagement) unmarshalConfigsLogError(ctx context.Context) func(*konf.Config) {
return func(konfCfg *konf.Config) {
go func() {
// some code...
err := c.unmarshalConfigs(konfCfg)
if err != nil {
c.logger.ErrorContext(ctx, "c.unmarshalConfigs():", slogAttrError(err))
}
// some code...
}()
}
}
I believe the problem was in this new routine in the hook.
I believe it has been fixed in #378
Fixed data race occurred in
*Config.values
,*Config.providers
andprovider.values
.go test
log: