lxd: wait for on-going refreshes to finish
Metadata
Current evaluation
Merged fix adding a snap watch call before injecting snaps into LXD containers to wait for ongoing refreshes. Resolves race conditions causing build failures in issues #2037 and LP: #1722049. Approved by reviewer and passed CI.
Suggested action: —
No scores available.
Issue body
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on [bug reports](https://bugs.launchpad.net/snapcraft)?
- [x] If this is a new feature. Have you discussed the design on the [forum](https://forum.snapcraft.io)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh unit`?
-----
This PR adds a `snap watch` call before injecting (core and snapcraft) snaps into the LXD container to force any on-going refreshes to be done.
Fixes: #2037
Fixes: [LP: #1722049](https://bugs.launchpad.net/snapcraft/+bug/1722049)
The following tests were updated:
- tests.unit.test_lxd.test_inject_snap
- To verify that the `snap watch` call is made first.
I locally ran the tests:
- `./runtests.sh tests/unit` with unrelated failures in [tests.unit.test_lifecycle.CoreSetupTestCase.test_core_setup_if_docker_env](https://bugs.launchpad.net/snapcraft/+bug/1752576), `tests.unit.test_mangling.TestClearExecstack.test_execstack_clears` and `tests.unit.test_elf`.
- `./runtests.sh tests/integration` with one unrelated failure in [tests.integration.general.test_parser.TestParserWikis](https://bugs.launchpad.net/snapcraft/+bug/1752580)
- `./runtests.sh static`: Everything passed
Manual testing:
- Testing this is a bit tricky because by design it's a race. First prepare a new container *running Snapcraft as a snap from this branch*.
- SNAPCRAFT_CONTAINER_BUILDS=1 snapcraft pull
- Run the following commands in tandem repeatedly to see that it won't cause a problem. Pick different channels for CHANNEL below eg. `--edge` or `--beta` to alternate so that refreshes won't be no-ops. Running this twice will confirm that there are indeed changes in progress, making Snapcraft fail without the fix.
- lxc start snapcraft-basic
- lxc exec snapcraft-basic -- snap refresh core --edge --no-wait
- lxc exec snapcraft-basic -- snap refresh core --edge --no-wait
- SNAPCRAFT_CONTAINER_BUILDS=1 snapcraft pull
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| qwen/qwen3.6-35b-a3b | — | — | Merged fix adding a snap watch call before injecting snaps into LXD containers to wait for ongoing refreshes. Resolves race conditions causing build failures in issues #2037 and LP: #1722049. Approved by reviewer and passed CI. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged a fix that adds a snap watch call to wait for ongoing refreshes before injecting core and snapcraft snaps into LXD containers, resolving race conditions in issues #2037 and LP: #1722049. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Merged. Introduces a snap watch call before injecting snaps into LXD containers, ensuring ongoing refreshes complete first and resolving race conditions in #2037 and LP: #1722049. |
Update history
No update history recorded yet.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1412 lxd: snapcraft refresh in containers | snapcraft | merged | Merged after awaiting prerequisite PR #1627. Implements snapcraft refresh for LXD containers, updating apt cache and packages once to persist changes across builds. Resolves container update persistence issues following successful testing. | |
| #1865 lxd: always (re-)injects snaps | snapcraft | merged | Merged to fix LP: #1741752 by ensuring LXD containers always re-inject snaps. Changes refactor injection logic, reorganize files, and properly handle side-loaded snap assertions. Approved by reviewer and passed CI. | |
| #1739 lxd: refresh remote container | snapcraft | merged | Fixes snapcraft refresh to correctly target the remote LXD container specified in SNAPCRAFT_CONTAINER_BUILDS instead of defaulting to local. Merged after approval and successful testing. | |
| #1577 lxd: don't inject local snaps on a different arch | snapcraft | merged | Merged a fix preventing Snapcraft from injecting local snaps into LXD containers with mismatched architectures. Cross-arch remotes now install snaps from the store. Approved by reviewers and merged after CI checks. | |
| #1568 lxd: don't re-inject the same snaps | snapcraft | merged | Merged a fix for an LXD bug that repeatedly re-injected identical snaps due to mismatched revision filenames. The change resolves the issue by comparing snap hashes instead of relying on filename matching, preventing unnecessary reinstallations. | |
| #1435 lxd: wait on lock files before running apt commands | snapcraft | merged | Merged a change that waits for apt lock files before executing apt commands in LXD. This prevents concurrent lock errors when apt runs simultaneously with snapcraft. Approved by two reviewers with a 12/-3 line diff. | |
| #1263 lxd: pass through commands into the container | snapcraft | merged | Merged a pull request enabling snapcraft to pass build commands into LXD containers. The change allows remote builds to execute within the container environment, addressing path mounting issues during remote snap creation. Approved by one reviewer, though coverage decreased slightly. | |
| #1984 fix(snap): check if LXD is actually installed | charmcraft | merged | Merged fix updating configure and remove hooks to verify LXD installation before proceeding. Prevents unwanted LXD snap installations on Ubuntu that cause delays. Approved by two reviewers, passed CI, and resolves #1982. | |
| #1364 lxd: Inject snapcraft and core snaps into the container | snapcraft | merged | Merged. Injects the host's snapcraft and core snaps into LXD containers to ensure build version consistency. Approved by one reviewer, modifying nine files with 360 additions and 46 deletions. | |
| #1519 lxd: use a unique temporary folder | snapcraft | merged | Merged to resolve parallel snapcraft cleanbuild failures by moving the temporary folder initialization to the constructor. Removed the is_snap condition, relocated tests, and passed CI review. Modified 5 files. |