Randomly I get "failed to inject host's snap 'snapcraft' into target environment." errors
Metadata
Current evaluation
Random host-snap injection failures were fixed by canonical/craft-providers PR #182 and released in Snapcraft 7.3.
Resolution: closed resolved
Reason: The craft-providers fix in canonical/craft-providers#182 waits for snap auto-refreshes before injection. It shipped in Snapcraft 7.3 after the blocking snapd bug was fixed in 2.58.3.
Evaluated by: mr-cal-bot
No scores available.
Issue body
I get errors ramdomly while trying to build core22-based snaps, maybe like 50% of the times:
$ snapcraft
Launching instance... \ (4.5s) Traceback (most recent call last):
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/actions/snap_installer.py", line 320, in inject_from_host
executor.execute_run(
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
return self.lxc.exec(
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 329, in exec
return runner(final_cmd, **kwargs) # pylint: disable=subprocess-run-check
File "/snap/snapcraft/8567/usr/lib/python3.8/subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-network-manager-on-amd64-for-amd64-50205072', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'SNAPCRAFT_MANAGED_MODE=1', 'SNAPCRAFT_BUILD_INFO=y', 'snap', 'install', '/tmp/snapcraft.snap', '--classic']' returned non-zero exit status 10.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 480, in _install_snaps
snap_installer.inject_from_host(
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/actions/snap_installer.py", line 328, in inject_from_host
raise SnapInstallationError(
craft_providers.actions.snap_installer.SnapInstallationError: failed to install snap 'snapcraft'
* Command that failed: 'lxc --project snapcraft exec local:snapcraft-network-manager-on-amd64-for-amd64-50205072 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 SNAPCRAFT_BUILD_INFO=y snap install /tmp/snapcraft.snap --classic'
* Command exit code: 10
* Command standard error output: b'error: snap "snapcraft" has "auto-refresh" change in progress\n'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 126, in launched_environment
instance = launch(
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 176, in launch
base_configuration.warmup(executor=instance)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 395, in warmup
self._install_snaps(executor=executor, deadline=deadline)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 486, in _install_snaps
raise BaseConfigurationError(
craft_providers.bases.errors.BaseConfigurationError: failed to inject host's snap 'snapcraft' into target environment.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/snap/snapcraft/8567/bin/snapcraft", line 8, in <module>
sys.exit(run())
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/cli.py", line 228, in run
_run_dispatcher(dispatcher)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/cli.py", line 204, in _run_dispatcher
dispatcher.run()
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_cli/dispatcher.py", line 448, in run
return self._loaded_command.run(self._parsed_command_args)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 259, in run
super().run(parsed_args)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 132, in run
parts_lifecycle.run(self.name, parsed_args)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 208, in run
_run_command(
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 249, in _run_command
_run_in_provider(project, command_name, parsed_args)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 530, in _run_in_provider
with provider.launched_environment(
File "/snap/snapcraft/8567/usr/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 140, in launched_environment
raise LXDError(str(error)) from error
craft_providers.lxd.errors.LXDError: failed to inject host's snap 'snapcraft' into target environment.
I can usually build by just retrying to run snapcraft.
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Random host-snap injection failures were fixed by canonical/craft-providers PR #182 and released in Snapcraft 7.3. | |
| stealth/space-bunny-alpha | — | closed resolved | Random "failed to inject host's snap 'snapcraft'" errors were a craft-providers bug (auto-refresh change in progress). Fixed by canonical/craft-providers#182, released in snapcraft 7.3. | |
| stealth/space-bunny-alpha | — | closed stale | Closed without a documented fix or linked PR; logs showed host Snapcraft injection failing during auto-refresh, and retrying usually worked. | |
| qwen/qwen3.6-35b-a3b | — | — | Abandoned due to inactivity. The report described intermittent snapcraft build failures triggered by snap auto-refresh conflicts during LXD environment injection. No fix was implemented. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without resolution, likely abandoned due to inactivity. The failure occurs randomly when snapcraft's auto-refresh blocks LXD environment injection. Retrying the build works around the issue. No fix or merge was applied. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without resolution. The report describes a race condition where snapcraft fails to inject the snap due to an ongoing auto-refresh change. With zero comments and no fix provided, the issue was likely abandoned due to inactivity. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without resolution. The race condition between snap installation and auto-refresh during environment injection remains unfixed. Workaround involves retrying builds. |
Update history
| Date | Change |
|---|---|
| created |
Related work
-
Likely Fixed By:
canonical/craft-providers#182
(confidence 99%)
Imported the refresh-wait behavior into craft-providers.
-
Related To:
canonical/craft-providers#174
(confidence 98%)
Original report of the same auto-refresh race condition.
-
Blocked By:
snapcraft (launchpad)#2002835
(confidence 98%)
The snapd bug delayed release until snapd 2.58.3 fixed it.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1064 fix: skip injecting snaps from host when cross-building | craft-application | closed | Closed as redundant after the same cross-build snap-injection fix merged in canonical/craft-application#1037 via commit 16bd7ac3. | |
| #1779137 build provider support to inject snaps on the host | snapcraft (launchpad) | closed | Build providers gained host-snap injection when Snapcraft runs from a snap; fixed by merged snapcore/snapcraft#2174 (commit 283ab0bb8). | |
| #1782778 Improve installation/injection logic for snapcraft (and core) | snapcraft (launchpad) | closed | Installation and host-injection logic was resolved in canonical/craft-providers PR #45, merged as commit 3573b67 under CRAFT-253. |