Snapcraft exit code 10

I am trying to build the pi-gadget snap on an amd64 host for arm64 with core22. I was able to build once and then made a change in the yaml file. Then, I issued snapcraft clean and tried to build again and got this message. From that point on, I’m stuck with the error. One thing that “seems” to allow me to rebuild is rebooting the host.

Launching instance... / (33.6s)                                                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-pi-on-amd64-for-arm64-6687790', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'SNAPCRAFT_MANAGED_MODE=1', '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-pi-on-amd64-for-arm64-6687790 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 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 212, in launch
base_configuration.setup(executor=instance)
  File "/snap/snapcraft/8567/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 354, in setup
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.

The error message snap "snapcraft" has "auto-refresh" change in progress suggests that I’m trying to build while the auto-refresh is in progress. However, I’m at a loss here. Any pointers to where to look for a solution would be highly appreciated.

you might need this PR:

Thanks for the report, @rasid.

This issue was recently raised in the craft-providers library. The problem is that we aren’t disabling auto-refresh when building core22 snaps.

I haven’t able to reproduce the failure, so I don’t have a good workaround. I believe when this happens, the container is still running, which would mean the snap refresh should complete after a few minutes and the next run of snapcraft would be successful.

If that doesn’t work, then the not-so-pretty workaround is going to be to run snapcraft clean and delete the cached LXD image (which you can see with lxc --project snapcraft image list).