archive: fix race condition in cmdStream#39860
Merged
cpuguy83 merged 1 commit intomoby:masterfrom Sep 12, 2019
Merged
Conversation
|
Please sign your commits following these rules: $ git clone -b "cmd-race" [email protected]:stbenjam/moby.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -fAmending updates the existing PR. You DO NOT need to open a new one. |
42502e6 to
70ccc74
Compare
Member
|
ping @kolyshkin @tiborvass PTAL |
tiborvass
reviewed
Sep 10, 2019
Contributor
|
Another way to find the race is to run |
There is a race condition in pkg/archive when using `cmd.Start` for pigz and xz where the `*bufio.Reader` could be returned to the pool while the command is still writing to it, and then picked up and used by a new command. The command is wrapped in a `CommandContext` where the process will be killed when the context is cancelled, however this is not instantaneous, so there's a brief window while the command is still running but the `*bufio.Reader` was already returned to the pool. wrapReadCloser calls `cancel()`, and then `readBuf.Close()` which eventually returns the buffer to the pool. However, because cmdStream runs `cmd.Wait` in a go routine that we never wait for to finish, it is not safe to return the reader to the pool yet. We need to ensure we wait for `cmd.Wait` to finish! Signed-off-by: Stephen Benjamin <[email protected]>
Member
|
@tiborvass @kolyshkin PR was updated; PTAL |
tiborvass
approved these changes
Sep 12, 2019
Contributor
|
FYI a followup to this PR is in #39920 |
This file contains hidden or 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
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.
- What I did
Fixed a race condition, see details in issue #39859
- How I did it
Ensured that
cmd.Waitis done, before any clean up happens.- How to verify it
There is a reproducer at https://github.com/stbenjam/docker-race-reproducer. Run the code as-is, and then apply the changes in this PR to vendor/github.com/docker/docker/pkg/archive/archive.go. You'll see the issue is fixed.
- Description for the changelog
Fixed a race condition in cmdStream to ensure that we wait for the command to exit before any clean up.
- A picture of a cute animal (not mandatory but encouraged)
My dog, Tilly: