Skip to content

Attempt to fix buildx/multiarch build flakiness - #15386

Merged
mattklein123 merged 3 commits into
envoyproxy:mainfrom
arkodg:use-binfmt
Mar 11, 2021
Merged

mattklein123 merged 3 commits into
envoyproxy:mainfrom
arkodg:use-binfmt

Conversation

@arkodg

@arkodg arkodg commented Mar 9, 2021 •

Copy link
Copy Markdown
Contributor

Hit this multiarch build issue on a seperate PR
#15204 (comment)

Fixes #14971

Most likely relates to docker/buildx#542

https://github.com/docker/buildx#building-multi-platform-images
recommends running docker run --privileged --rm tonistiigi/binfmt --install all before setting up buildx

Signed-off-by: Arko Dasgupta [email protected]

Risk Level: Low
Testing: CI

@arkodg

arkodg commented Mar 9, 2021

Copy link
Copy Markdown
Contributor Author

cc @lizan @phlax @tonistiigi

@dio dio assigned lizan and phlax Mar 10, 2021
@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

there is a ticket tracking the issue this is addressing here #14971

@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

i have no objection to this change altho im not clear whether it will resolve anything

reading the upstream docs (https://github.com/docker/buildx#building-multi-platform-images):

For QEMU binaries registered with binfmt_misc on the host OS to work transparently inside containers they must be registered with the fix_binary flag. This requires a kernel >= 4.8 and binfmt-support >= 2.1.7. You can check for proper registration by checking if F is among the flags in /proc/sys/fs/binfmt_misc/qemu-*. While Docker Desktop comes preconfigured with binfmt_misc support for additional platforms, for other installations it likely needs to be installed using tonistiigi/binfmt image.

im wondering whether it would work at all if there was not binfmt_misc support

esp given the command runs --privileged it would be good to confirm the necessity - is there a before/after command that we can run to check whether support is/not present ?

@arkodg

arkodg commented Mar 10, 2021

Copy link
Copy Markdown
Contributor Author

the multiarch CI step passed so this image does seem to work and install the right things (QEMU emulators) needed
I decided to add this since it seems to be the recommended way to use buildx for building multiarch and then tackle the flakiness if it continues to persist
unsure if it will fix the build flakiness, one way to check is to rerun this CI a few times :), I dont have rights to do that unfortunately

@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

rerunning probs wont help - as its a flake - its kinda random (or at least indeterminate) when it will fail

also - the links posted here #14971 suggest it might be a memory issue, and specifically that rerunning is likely to make it work (if it is indeed the problem that is discussed in those links)

@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

in terms of tracking down the flake im wondering if we can dump state (mem/disk free ?) before/after running buildx

ideally we want to know what is going wrong when it fails and this might show a difference

it might be that it has nothing to do with memory etc and its just a network error that is exposed because buildx runs the build recipes multiple times and the upstream repos are flakey

@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

this is the command to check what is (already) installed, and the output on my local machine:

$ docker run --privileged --rm tonistiigi/binfmt
Unable to find image 'tonistiigi/binfmt:latest' locally
latest: Pulling from tonistiigi/binfmt
b2cca52c34c9: Pull complete 
6247d1dfaecd: Pull complete 
Digest: sha256:c94a8dab5c7d9913687e77f529fc2a487dcb6aaea2f040e588cfebd778ebcb1a
Status: Downloaded newer image for tonistiigi/binfmt:latest
{
  "supported": [
    "linux/amd64",
    "linux/386"
  ],
  "emulators": null
}

@phlax

phlax commented Mar 10, 2021

Copy link
Copy Markdown
Member

try adding that command before/after your addition and see if anything changes

@arkodg

arkodg commented Mar 10, 2021

Copy link
Copy Markdown
Contributor Author

docker/buildx#542 might be what we're hitting here and might need to add docker run --rm --privileged tonistiigi/binfmt --uninstall qemu-aarch64 before docker run --privileged --rm tonistiigi/binfmt --install all

testing it out rn

@arkodg
arkodg force-pushed the use-binfmt branch 2 times, most recently from 3ff9f51 to be2ad68 Compare March 10, 2021 19:53
@arkodg

arkodg commented Mar 10, 2021 •

Copy link
Copy Markdown
Contributor Author

here are the logs

pre-install

status: Downloaded newer image for tonistiigi/binfmt:latest
{
  "supported": [
    "linux/amd64",
    "linux/386"
  ],
  "emulators": [
    "cli",
    "jar",
    "python2.7",
    "python3.6"
  ]
}

removing qemu-aarch64 does not help here, but it might be good to have since someone else might be installing the buggy qemu emulator (not verified, just a hunch), mentioned in the buildx issue

2021/03/10 21:48:35 uninstalling: qemu-aarch64 not found

post-install

2021/03/10 21:48:36 installing: ppc64le OK
2021/03/10 21:48:36 installing: riscv64 OK
2021/03/10 21:48:36 installing: mips64el OK
2021/03/10 21:48:36 installing: mips64 OK
2021/03/10 21:48:36 installing: arm64 OK
2021/03/10 21:48:36 installing: arm OK
2021/03/10 21:48:36 installing: s390x OK
{
  "supported": [
    "linux/amd64",
    "linux/arm64",
    "linux/riscv64",
    "linux/ppc64le",
    "linux/s390x",
    "linux/386",
    "linux/mips64le",
    "linux/mips64",
    "linux/arm/v7",
    "linux/arm/v6"
  ],
  "emulators": [
    "cli",
    "jar",
    "python2.7",
    "python3.6",
    "qemu-aarch64",
    "qemu-arm",
    "qemu-mips64",
    "qemu-mips64el",
    "qemu-ppc64le",

Hit this multiarch build issue on a seperate PR
envoyproxy#15204 (comment)

Fixes envoyproxy#14971

Most likely relates to docker/buildx#542

https://github.com/docker/buildx#building-multi-platform-images
recommends running `docker run --privileged --rm tonistiigi/binfmt
--install all` before setting up `buildx`

Signed-off-by: Arko Dasgupta <[email protected]>
@arkodg

arkodg commented Mar 10, 2021 •

Copy link
Copy Markdown
Contributor Author

also multiarch/qemu-user-static moved to qemu 5.2 multiarch/qemu-user-static@d9c81fc which is known to have the flakiness regression mentioned here docker/buildx#542 (comment)

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

removing qemu-aarch64 does not help here, but it might be good to have since someone else might be installing the buggy qemu emulator (not verified, just a hunch), mentioned in the buildx issue

that doesnt look like the issue then

post-install

that does seem to install support - not sure how it would work without this

moved to qemu 5.2...

not sure but is there anything in the error messages etc which aligns ?

@arkodg

arkodg commented Mar 11, 2021

Copy link
Copy Markdown
Contributor Author

from docker/buildx#542 (comment) the issue is related to qemu 5.2 present in
multiarch/qemu-user-static which is causing the occasional seg fault
This PR uses tonistiigi/binfmt which is pinned to qemu-v5.0.1 until the qemu issue is resolved, to solve the issue
I have also added the docker run --rm --privileged tonistiigi/binfmt --uninstall qemu-aarch64 command to ensure anything
installed before has been cleaned up correctly

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

I have also added the docker run --rm --privileged tonistiigi/binfmt --uninstall qemu-aarch64 command to ensure anything

if its not installed already i think dont add it - its just going to muddy the water

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

@arkodg im keen not to make changes unless it genuinely fixes something

this flake is v annoying - its ~random, happens quite often and happens half way through the ci run

i think once we find a ~fix for this we want to run the ci repeatedly with small changes to see if its really fixed

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

also please dont force push once someone is reviewing your code

Signed-off-by: Arko Dasgupta <[email protected]>
@arkodg

arkodg commented Mar 11, 2021

Copy link
Copy Markdown
Contributor Author

ok, ive reverted uninstalling qemu-aarch64
pretty sure this PR should fix the CI issue and happy to revert #15204 as well which
was not related to the CI flakiness imho

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

pretty sure this PR should fix the CI issue

which bit ?

if you think we have a fix im happy to test it further

...which was not related to the CI flakiness imho

yep defo my opinion too - and it would seem the facts on the ground

i think dont revert tho as there were other reasons for moving the su-exec compile

@arkodg

arkodg commented Mar 11, 2021

Copy link
Copy Markdown
Contributor Author

pretty sure this PR should fix the CI issue

which bit ?
#15386 (comment)

Comment thread ci/docker_ci.sh
# Qemu configurations
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
# Install QEMU emulators
docker run --rm --privileged tonistiigi/binfmt --install all

@phlax phlax Mar 11, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i need to understand better what is changed here

is tonistiigi/binfmt --install all a dropin replacement for multiarch/qemu-user-static --reset -p yes ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

@phlax phlax Mar 11, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread ci/docker_ci.sh Outdated
# Remove older build instance
docker buildx rm multi-builder || :
docker buildx create --use --name multi-builder --platform linux/arm64,linux/amd64
docker buildx create --use --name multi-builder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this not stop it from building for arm ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

platforms can be autodetected - https://github.com/docker/buildx#--platform-platforms

docker "${BUILD_COMMAND[@]}" --platform "${PLATFORM}" "${args[@]}" -t "${BUILD_TAG}" .
does the buildx build for the ARCH specified

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

platforms can be autodetected

lets keep this explicit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fwiw manually setting it is not recommended unless you know what you are doing. This will override the detection meaning that if you don't actually have a proper setup build will still be attempted and will fail with some exec format error deeper in the stack. The main case where this flag is used is to set arch priorities for multi-node build clusters but that does not seem to be your use-case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 thanks for clarifying :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@arkodg do you want to create a pr to update ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will override the detection meaning that if you don't actually have a proper setup build will still be attempted and will fail with some exec format

which in a way we want as long as it fails so the setup can be fixed - these are the architectures we want and only want

not sure if the combination of doing --install all and not specifying this means it would create lots of images that dont get published, but lets see

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yah --install all would setup emulators for all supported architectures, not build all images, that is governed by the buildx bake cmd
If we want to have a more cautious and a fail fast and early approach, we should only install for linux/arm64

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i see

Signed-off-by: Arko Dasgupta <[email protected]>
@phlax

phlax commented Mar 11, 2021 •

Copy link
Copy Markdown
Member

@arkodg ive opened a PR to test possible fixes here #15428

atm it just starts the docker build more quickly

im going to run it say 5 times (lets see) and watch for build failures

once that is done, i will pick your fix and see what happens

this is going to take a while - but be assured if we fix this others will be very happy

i read more the issue you linked to and found the possible fix from (docker/buildx#542)

its hard to say - but it does look like a possible candidate issue - lets see...

@phlax

phlax commented Mar 11, 2021 •

Copy link
Copy Markdown
Member

after getting bored running the above PR without fail and reading here https://medium.com/@artur.klauser/building-multi-architecture-docker-images-with-buildx-27d80f7e2408 the following:

As an alternative to installing the QEMU and binfmt-support packages on your host system you can use a docker image to satisfy the corresponding requirements. There are several docker images that do the job, among them multiarch/qemu-user-static and docker/binfmt. They come loaded with QEMU simulators for several architectures and their own setup script for installing those QEMU simulators in the host kernel’s binfmt_misc with the fix-binary (F) flag.

i understand a little better now how this is working, and that the image/command is ~equivalent

@phlax phlax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, thanks @arkodg

@mattklein123

Copy link
Copy Markdown
Member

@phlax sorry so you tested this and you think we should try it out?

@mattklein123 mattklein123 self-assigned this Mar 11, 2021
@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

@phlax sorry so you tested this and you think we should try it out?

its tested in ci - so it works in terms of producing docker images and then running verify etc (im assuming that the arm builds are correct, but no reason to think otherwise)

in terms of best approach to buildx - i think this PR is correct at time of commenting 8/

@phlax

phlax commented Mar 11, 2021 •

Copy link
Copy Markdown
Member

in terms of fixing the docker flake - lets hope so!

it hits about 1 in 10 builds so we should see pretty quickly, i came to the conclusion - that @arkodg had already come to - that trying out these newer versions of binfmt tools may well fix the issue - but was a good idea anyway (edited)

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you 🤞

@mattklein123
mattklein123 merged commit e20957c into envoyproxy:main Mar 11, 2021
@arkodg

arkodg commented Mar 11, 2021

Copy link
Copy Markdown
Contributor Author

thanks for testing it out @phlax

my conclusion is the opposite :), the latest multiarch/qemu-user-static image is buggy since it includes the buggy QEMU version (5.2), not only is tonistiigi/binfmtimage the recommended way to setup the QEMU emulators mentioned in the buildx repo, it also has proactively pinned the QEMU version to a older correct version qemu-v5.0.1 . So this a good change to fix the CI flakiness (due to the QEMU segfault bug), and for long term as well

@phlax

phlax commented Mar 11, 2021

Copy link
Copy Markdown
Member

and for long term as well

i think my hesitation is that it seems unofficial - even if it is a core devs image etc

not sure if multiarch is any more official tho without checking further

thanks again for figuring out a way forward

lets hope it resolves the immediate problem

aunu53 pushed a commit to aunu53/envoy that referenced this pull request Mar 19, 2021
Hit this multiarch build issue on a seperate PR
envoyproxy#15204 (comment)

Fixes envoyproxy#14971

Most likely relates to docker/buildx#542

https://github.com/docker/buildx#building-multi-platform-images
recommends running `docker run --privileged --rm tonistiigi/binfmt
--install all` before setting up `buildx`

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: Auni Ahsan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker linux multiarch ci test fails randomly

5 participants