Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't look too closely how these are called, but if both
DirandSetDirare called at the same time from different goroutines, we still might have a race condition:SetDirDirDoand "locks"initConfigDirfirst.Doblock.initConfigDirand unblocks Y, but doesn't enter the57: configDir = filepath.Clean(dir)yet45: return configDirand returns empty directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be ignored if we definitely don't (and won't) call these concurrently though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we would hit that case in our code, so I'm "fine" with it not 100% being race-free (per our discussion on slack; there's no deadlock, so not "worse" than before).
FWIW; I went through a couple of options;
sync/atomic.ValueBoth of those performed a lot less, and both are still somewhat tapering over the "big elephant in the room"; we shouldn't use a package-level variable for this.
So I'm also looking at removing this variable altogether in favour of this being a config for the client that's configured, as (looking at the code) that's where it's used, and I think the expectation is to set the location for the client that's constructed;
cli/cli/command/cli.go
Lines 209 to 221 in a26e601