-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix: potential deadlock #125
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes potential deadlock in containerd#123 Signed-off-by: Steven Kreitzer <[email protected]>
ee0ed6e
to
a94c4cc
Compare
This was referenced Dec 23, 2024
Merged
smira
added a commit
to smira/go-cni
that referenced
this pull request
Dec 24, 2024
There were at least two code paths which might acquire `.RLock()` recursively: 1. `Setup*()` -> `createResult()` 2. `Setup*()` -> `Networks()`. On its own, it's not a problem, but if `.Load()` is called concurrently, it might do `.Lock()` in between recursive `.RLock()`s, which would lead to a deadlock. See containerd#125 Fix by introducing a contract on the way mutex is acquired. Add a test facility to verify for such mistakes via build tags: * `go test -race` or `go test -tags deadlocks` activates deadlock detection Signed-off-by: Andrey Smirnov <[email protected]>
smira
added a commit
to smira/go-cni
that referenced
this pull request
Dec 24, 2024
There were at least two code paths which might acquire `.RLock()` recursively: 1. `Setup*()` -> `createResult()` 2. `Setup*()` -> `Networks()`. On its own, it's not a problem, but if `.Load()` is called concurrently, it might do `.Lock()` in between recursive `.RLock()`s, which would lead to a deadlock. See containerd#125 Fix by introducing a contract on the way mutex is acquired. Add a test facility to verify for such mistakes via build tags: * `go test -race` or `go test -tags deadlocks` activates deadlock detection Signed-off-by: Andrey Smirnov <[email protected]>
smira
reviewed
Dec 24, 2024
@@ -183,8 +181,6 @@ func (c *libcni) SetupSerially(ctx context.Context, id string, path string, opts | |||
if err := c.ready(); err != nil { | |||
return nil, err | |||
} | |||
c.RLock() |
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 this is totally correct (removing the lock), at least it's not clear if it is, see #126
Closing in favor of #126 |
smira
added a commit
to smira/pkgs
that referenced
this pull request
Dec 24, 2024
Fixes siderolabs/talos#9984 Patch with containerd/go-cni#126 See also: * containerd/go-cni#125 * containerd/containerd#11186 * containerd/go-cni#123 Signed-off-by: Andrey Smirnov <[email protected]>
smira
added a commit
to smira/pkgs
that referenced
this pull request
Dec 26, 2024
Fixes siderolabs/talos#9984 Patch with containerd/go-cni#126 See also: * containerd/go-cni#125 * containerd/containerd#11186 * containerd/go-cni#123 Signed-off-by: Andrey Smirnov <[email protected]> (cherry picked from commit 0b00e86)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This will fix the potential deadlock in #123
I'm not entirely sure why these excess locks were added.
Status()
was basically renamed toready()
, and thenSetup()
,SetupSerially()
,Remove()
, andCheck()
have added the additional lock mutexes below thec.ready()
, which were not present with the previousStatus()
code.You can see them before the change here:
Status()
ready()
Setup()
and so on...