Snapcraft concurrent build

Bug #1889741 reported by Lawrence Gripper
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Snapcraft
Confirmed
Undecided
Chris Patterson

Bug Description

When running multiple instances of snapcraft concurrently there is a race condition in the `$HOME/.cache/snapcraft/download` and `stage-packages` creation.

Kicking off multiple instances of snapcraft where snapcraft hasn't already been run (like a CI system) causes a concurrency bug in the snapcraft python where two instances enter the check for the folders existing, both see the folder doesn't exist, then the first instance creates it and the second instance fails attempting to create it as it's already been done. Unlucky right?

I wanted proof - the way I proved it was to test with a single instance starting for snapcraft and it fixed it. Also pre-creating the folders with `mkdir -p` before launching snapcraft also resolves the issue.

For more details on the bug: https://github.com/goreleaser/goreleaser/issues/1715

I'm using snapcraft in docker following this guide here: https://snapcraft.io/docs/build-on-docker

Revision history for this message
Lawrence Gripper (lawrencegripper) wrote :

I looked at making a contribution to resolve the issue but the code responsible appears to be in the XDG package not in the snapcraft code on github. One option to resolve would be to update the docs for docker image to include the creation of those folders or use a different method to ensure they're creation, capturing a `FileExists` error and suppressing it.

Revision history for this message
Chris Patterson (cjp256) wrote :

Thank you Lawrence for the report and researching it!

Have you considered submitting a patch upstream to fix this race condition? https://gitlab.freedesktop.org/xdg/pyxdg

Failing to be able to pull an upstream fix, we'll have to workaround it...

Changed in snapcraft:
status: New → Confirmed
assignee: nobody → Chris Patterson (cjp256)
Revision history for this message
Lawrence Gripper (lawrencegripper) wrote :

Yeah I had a look but it wasn't immediately obvious to me how to resolve in the XDG lib or whether it's the responsibility of that lib to work correctly in a concurrent situation vs Snapcraft handle some sort of locking mechanism for config/setup and use of the cache dir. As this concurrency bug came up I wasn't sure if there are others present how the cache directory is used after creation. Do the multiple instances race on the items in the cache? If so would maybe lean towards locking in snapcraft rather than XDG.

Burnt more time than I could really allow getting to this point. I do try my best to help out where I can and contribute fixes but bit too far down the rabbit hole for me on this one - sorry :(

Revision history for this message
Lawrence Gripper (lawrencegripper) wrote :

(for reference python isn't my strongest language so all of this maybe super simple to someone with more experience building larger things in python - tend to work with small scripts).

Revision history for this message
Carlos Alexandro Becker (caarlos0) wrote :
Revision history for this message
Tom Payne (twpayne) wrote :
Revision history for this message
Till Klampaeckel (till-php) wrote :

Back in 8.0.5

Revision history for this message
Victor RB (vroldanbet) wrote :

We've experienced this issue using 8.2.12 via goreleaser

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.