-
Notifications
You must be signed in to change notification settings - Fork 58
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
Refine usage of defer in config #426
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
@arcanericky, thanks for your great investigation. It's much appreciated!. |
Yes, your solution works great and is simpler than I thought it would be. I'm sure it was overlooked here because in at least a few locations I see where your solution is coded and avoids the problem, though I have found a few more "opportunities". In the case of |
It's important when you review this to keep in mind the original intention may be to have the return values from the function calls in the If this is the case, you should dismiss this PR or have me withdraw it. |
I've reverted to allowing the function calls in the |
Hi, @arcanericky. I created a new PR with the above improvements on all of the appearances of the unlock function that exists on the entire project with an explanatory comment. |
Your PR looks good @sverdlov93. One of you can close this PR or I will shut it down at your request. |
@arcanericky Thanks again for your contribution and your feedback! |
Refine atomic config command changes in
common/commands/ConfigCommand.Run()
, int #367, and also mentioned in #352.Change Details
defer
statements when possible. Note that I've accounted fordefer
executing in LIFO order.defer
of the anonymous functon containing thelockFile.Unlock()
gets executed after the return but before the function returns to the caller (https://go.dev/ref/spec#Defer_statements). This means the setting and check fore
not beingnil
and settingerr
have no effect on what is returned as might be the intention. See below for more. This change refines the code while leaving the current behavior in place because I know a lot of work went into shoring up the file lock race conditions. If returning an error fromlockFile.Unlock()
is the intention, more invasive changes must be made, and this isn't the only usage of this pattern (again, see below).gofmt
that's part of1.17.11
really wants to reorganize the imports so I left those changes in since the README explicity states to usegofmt
./
in the comment as mentioned in Fixing config file lock mechanism #352 (comment).For bullet point number 2, I see this pattern scattered throughout the code base:
Where it is expected that when the surrounding function returns
err
, could contain theerr
value set in thedefer
. This is not correct. You can observe the true behavior by running the following code which I've also placed in the Go Playground at https://go.dev/play/p/gOQB-jPRu4B:which outputs