Skip to content
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

Avoid bind-mounts for docker environments on macOS #18225

Merged
merged 6 commits into from
Feb 14, 2023

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Feb 11, 2023

Bind mounts in Docker for macOS have been implemented in a variety of ways over time, and are still in flux (https://www.cncf.io/blog/2023/02/02/docker-on-macos-is-slow-and-how-to-fix-it/ is a good overview of the chaos). But the gRPC FUSE implementation which is the default in the most recently released version at the time of writing (4.16.2) can suffer from race conditions where files which are created on the host inside a bind mount may not be visible to the container. This causes issues like #18162.

To avoid race conditions for file inputs, this change introduces a "pipe" IO strategy for Docker inputs, which uses a tar-pipe (from a tar-file stream written by the Store, to an exec of tar inside the container) to write process inputs. This strategy is used by default on macOS (for now), but the choice of strategy can be overridden.

The pipe IO strategy is about 30% slower for test running than the mount strategy. As we gather feedback from macOS users, we should be able to gain a clearer picture of which Docker for macOS versions and filesystem implementations can safely use the mount strategy.

Fixes #18162.

@stuhood stuhood added needs-cherrypick category:bugfix Bug fixes for released features labels Feb 11, 2023
@stuhood stuhood added this to the 2.15.x milestone Feb 11, 2023
@stuhood stuhood force-pushed the stuhood/tar-pipe-docker-macos branch 5 times, most recently from 76482c7 to caf3651 Compare February 12, 2023 22:06
@stuhood stuhood force-pushed the stuhood/tar-pipe-docker-macos branch 2 times, most recently from 0360272 to 5c3cacc Compare February 13, 2023 00:39
…sed, to avoid Docker bind mount confusion.
@stuhood stuhood force-pushed the stuhood/tar-pipe-docker-macos branch from e7c27cb to 387f89f Compare February 13, 2023 22:33
@stuhood stuhood requested review from huonw, jsirois and tdyas February 13, 2023 22:46
@stuhood stuhood marked this pull request as ready for review February 13, 2023 22:47
@stuhood
Copy link
Member Author

stuhood commented Feb 13, 2023

Commits are useful to review independently: most of them are self explanatory, but the "Split prepare_workdir from prepare_workdir_digest" change is to allow for creating a complete digest of initial contents of a process's workdir, which can then be used consistently to materialize it either using materialize_directory or a tar-file.

@stuhood stuhood marked this pull request as draft February 13, 2023 23:00
@stuhood

This comment was marked as outdated.

@stuhood stuhood force-pushed the stuhood/tar-pipe-docker-macos branch 2 times, most recently from d2141fa to a55036d Compare February 14, 2023 00:03
@stuhood stuhood requested review from huonw, jsirois and tdyas February 14, 2023 00:03
@stuhood stuhood marked this pull request as ready for review February 14, 2023 00:04
@stuhood stuhood force-pushed the stuhood/tar-pipe-docker-macos branch from a55036d to 9a36c6c Compare February 14, 2023 00:15
}
DockerStrategy::Pipe => {
// NB: For now, we continue to materialize files into a bind mount, but we do so from
// within the container. This allows us to capture outputs without an additional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems logically very likely. In my reading this is a known bug we're just waiting for to happen without calling the shot in an issue, maybe do that and we get to work on it? This still feels like shipping known (slightly less) broken software.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems possible, yes. But since we haven't observed it yet, I'm gambling... in the interest of saving time and complexity (I hope).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my user hat on I definitely do not appreciate you gambling and not letting me know. I hope this will make a release announcement / acknowledgement - basically macOS Docker integration is known likely broken and you may see X.

Copy link
Contributor

@tdyas tdyas Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want a semi-reliable manual way to expose the bug, clone https://github.com/tdyas/pants-go-testing and then run ./pants package race:racy_docker repeatedly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(although "race" there refers to the Go data race detector, not this bug)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, missed your comment before merging @tdyas : but thanks, will try it.

.start_exec(&exec.id, None)
.await
.map_err(|err| format!("Failed to start Docker execution `{}`: {:?}", &exec.id, err))?;
let StartExecResults::Attached { mut output, mut input } = exec_result else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax is new to me. I'd expect an if let would be needed to support the else at the end. I feel like I'm reading scala and space can invoke a method and else is a method or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is let-else, but used with something other than Option: https://rust-lang.github.io/rfcs/3137-let-else.html

@stuhood stuhood merged commit c478a13 into pantsbuild:main Feb 14, 2023
@stuhood stuhood deleted the stuhood/tar-pipe-docker-macos branch February 14, 2023 17:28
stuhood added a commit to stuhood/pants that referenced this pull request Feb 14, 2023
stuhood added a commit that referenced this pull request Feb 14, 2023
…18247)

Symlink support in `Digest`s landed after `2.15.x` was cut, and is too
significant to cherry-pick. This reverts #18225. Will re-land a smaller
change which can be more easily picked.

This reverts commit c478a13.
illicitonion added a commit that referenced this pull request Feb 17, 2023
Internal changes:

* go: fix go vet test flakiness
([#18296](#18296)

* Add default gha 1000:1000 user to GHA images.
([#18281](#18281))

* Don't specify interpreter_constraints when building the release pex.
([#18280](#18280))

* go: update pass-through `go test` options for Go v1.20
([#18229](#18229))

* Fix release for /tmp on a seperate filesystem.
([#18272](#18272))

* upgrade to Rust v1.67.1
([#18269](#18269))

* Prepare the 2.15.0rc6 release.
([#18263](#18263))

* Allow lambdas for `Field` and `Target` help
([#18248](#18248))

* Revert "Avoid bind-mounts for docker environments on macOS (#18225)"
([#18247](#18247))

* Refactors `experimental_shell_command`-related files to better
separate concerns
([#18223](#18223))

* Prepare the 2.15.0rc5 release.
([#18224](#18224))

* Give dedicated threads names
([#18214](#18214))

* Prepare 2.15.0rc4.
([#18196](#18196))

* Remove the `boot_script` from
`experimental_shell_command`/`experimental_run_in_sandbox`
([#18168](#18168))

* Adjusts `BinaryShims` to use native digest operations and
`immutable_input_digests`
([#18184](#18184))

* go: update build tags check from latest go sources
([#18176](#18176))

* [internal] note dependency to `scie-pants` on "testing" env vars.
([#18170](#18170))

* go: allow coverage for standard library packages
([#18171](#18171))

* Support using `scie-pants` for Pants dev work.
([#18158](#18158))

* Prepare the 2.15.0rc3 release
([#18156](#18156))

* Splits up `shell_command.py`
([#18147](#18147))
seve-martinez pushed a commit to seve-martinez/pants that referenced this pull request Feb 20, 2023
…d#18225)" (pantsbuild#18247)

Symlink support in `Digest`s landed after `2.15.x` was cut, and is too
significant to cherry-pick. This reverts pantsbuild#18225. Will re-land a smaller
change which can be more easily picked.

This reverts commit c478a13.
seve-martinez pushed a commit to seve-martinez/pants that referenced this pull request Feb 20, 2023
Internal changes:

* go: fix go vet test flakiness
([pantsbuild#18296](pantsbuild#18296)

* Add default gha 1000:1000 user to GHA images.
([pantsbuild#18281](pantsbuild#18281))

* Don't specify interpreter_constraints when building the release pex.
([pantsbuild#18280](pantsbuild#18280))

* go: update pass-through `go test` options for Go v1.20
([pantsbuild#18229](pantsbuild#18229))

* Fix release for /tmp on a seperate filesystem.
([pantsbuild#18272](pantsbuild#18272))

* upgrade to Rust v1.67.1
([pantsbuild#18269](pantsbuild#18269))

* Prepare the 2.15.0rc6 release.
([pantsbuild#18263](pantsbuild#18263))

* Allow lambdas for `Field` and `Target` help
([pantsbuild#18248](pantsbuild#18248))

* Revert "Avoid bind-mounts for docker environments on macOS (pantsbuild#18225)"
([pantsbuild#18247](pantsbuild#18247))

* Refactors `experimental_shell_command`-related files to better
separate concerns
([pantsbuild#18223](pantsbuild#18223))

* Prepare the 2.15.0rc5 release.
([pantsbuild#18224](pantsbuild#18224))

* Give dedicated threads names
([pantsbuild#18214](pantsbuild#18214))

* Prepare 2.15.0rc4.
([pantsbuild#18196](pantsbuild#18196))

* Remove the `boot_script` from
`experimental_shell_command`/`experimental_run_in_sandbox`
([pantsbuild#18168](pantsbuild#18168))

* Adjusts `BinaryShims` to use native digest operations and
`immutable_input_digests`
([pantsbuild#18184](pantsbuild#18184))

* go: update build tags check from latest go sources
([pantsbuild#18176](pantsbuild#18176))

* [internal] note dependency to `scie-pants` on "testing" env vars.
([pantsbuild#18170](pantsbuild#18170))

* go: allow coverage for standard library packages
([pantsbuild#18171](pantsbuild#18171))

* Support using `scie-pants` for Pants dev work.
([pantsbuild#18158](pantsbuild#18158))

* Prepare the 2.15.0rc3 release
([pantsbuild#18156](pantsbuild#18156))

* Splits up `shell_command.py`
([pantsbuild#18147](pantsbuild#18147))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:bugfix Bug fixes for released features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing in Docker environment fails with pex FileNotFoundError
3 participants