-
Notifications
You must be signed in to change notification settings - Fork 207
Make FakeExec safe for concurrency #274
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
Conversation
|
Welcome @artemvmin! |
|
/assign @msau42 |
|
/lgtm |
|
/assign @dims |
exec/testing/fake_exec.go
Outdated
|
|
||
| // LookPath is for finding the path of a file | ||
| func (fake *FakeExec) LookPath(file string) (string, error) { | ||
| fake.mu.Lock() |
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 this lead to a lock ordering inversion or even just a recursive lock?
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.
Command() and LookPath() don't explicitly call each other. This means that once either function acquires a lock, it will be able to finish and unlock. Still, the caller could embed one method inside the other, which would cause deadlock.
I went ahead and tightened the lock to only the section violating the invariant, i.e. when CommandCalls is incremented and CommandScript accessed non-atomically.
There's still the implication that the fields in the fake object shouldn't be modified while it's being used in a concurrent context, but there are easier ways to make a brittle test.
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.
Thanks, I would also at least mention this in the documentation for the function that the risk exists.
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.
Good idea. Done.
ea2a921 to
e46aff0
Compare
e46aff0 to
fad585f
Compare
|
/approve @msau42 do you mind re-applying lgtm? Thanks! |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: apelisse, artemvmin, msau42 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR adds a mutex to the FakeExec struct.
The real executor shares no state between osexec.Command() calls. Meanwhile, FakeExec shares all the state stored on the struct.
I am working with a CSI driver that uses a single object for all provisioning calls. This change will allow me to test its behavior when calls are made concurrently.
This change is backwards compatible, since the existing behavior is undefined (and nondeterministic) for concurrent calls.
Release note: