Snapcraft error: failed to inject host's snap 'snapcraft' into target environment, exit code 1

I get this error on snapcraft --debug when I try to build a snap for a rust app. Running in sudo does not work.

Launching instance... | (171.8s)                                                                                   Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/actions/snap_installer.py", line 320, in inject_from_host
    executor.execute_run(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
    return self.lxc.exec(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 371, in exec
    return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
  File "/snap/snapcraft/9542/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-servicer-on-amd64-for-amd64-19537807', '--', '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 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 658, in _install_snaps
    snap_installer.inject_from_host(
  File "/snap/snapcraft/9542/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-servicer-on-amd64-for-amd64-19537807 -- 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: 1
* Command standard error output: b'error: cannot perform the following tasks:\n- Ensure prerequisites for "snapcraft" are available (cannot install snap base "core20": Post "https://api.snapcraft.io/v2/snaps/refresh": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers))\n'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 138, in launched_environment
    instance = launch(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 545, in launch
    _create_instance(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 74, in _create_instance
    base_configuration.setup(executor=instance)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 484, in setup
    self._install_snaps(executor=executor, deadline=deadline)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 664, 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/9542/bin/snapcraft", line 8, in <module>
    sys.exit(run())
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/cli.py", line 255, in run
    _run_dispatcher(dispatcher, global_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/cli.py", line 228, in _run_dispatcher
    dispatcher.run()
  File "/snap/snapcraft/9542/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/9542/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 265, in run
    super().run(parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 138, in run
    parts_lifecycle.run(self.name, parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 216, in run
    _run_command(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 262, in _run_command
    _run_in_provider(project, command_name, parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 556, in _run_in_provider
    with provider.launched_environment(
  File "/snap/snapcraft/9542/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 153, in launched_environment
    raise LXDError(str(error)) from error
craft_providers.lxd.errors.LXDError: failed to inject host's snap 'snapcraft' into target environment.

snapcraft.yaml

Here is the codebase for servicer. Feel free to try building locally to debug.

name: servicer # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: git # just for humans, typically '1.2+git' or '1.3.2'
summary: Simplify Service Management on systemd # 79 char long summary
description:  A CLI tool for service management on systemd.

apps:
  servicer:
    command: bin/servicer
    plugs: [home]

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

parts:
  servicer:
    # See 'snapcraft plugins'
    plugin: rust
    source: .

System details

  • OS: Lubuntu 23.04
  • lxd: 5.15
  • snapcraft: 7.5.2
  • processor: Intel® Core™ i5-6200U CPU @ 2.30GHz
snap    2.59.5
snapd   2.59.5
series  16
ubuntu  23.04
kernel  6.2.0-26-generic

Update: core20 worked but it built on multipass instead of lxd.

Glad you were able to use Multipass as a workaround.

Did this issue only occur with snapcraft 7.5.2? The line cannot install snap base "core20": Post "https://api.snapcraft.io/v2/snaps/refresh": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)) points to a network connectivity issue.

It could be a network issue with your LXD configuration (for example, docker and lxd could have mangled your iptables) or it could be a network issue with the snap store.

I installed snapcraft today so not sure about older versions. Shall downgrade to see if things work.

I see. No need to downgrade. 7.5.2 was released to stable yesterday and there were no changes involving LXD, but I wanted to confirm.

A likely culprit is that the LXD container does not have network connectivity to the snap store. Do you happen Docker installed?

It would be useful to see the log output of that core22 snap using LXD with snapcraft --verbosity=trace.

I have docker. Let me get the verbose logs. It seems like docker0 bridge was touched

image

Verbose logs

2023-08-08 18:50:01.262 Starting Snapcraft 7.5.2                                                                     
2023-08-08 18:50:01.262 Logging execution to '/home/hp/.local/state/snapcraft/log/snapcraft-20230808-185001.261118.log'                                                                                                                    
2023-08-08 18:50:01.262 Raw pre-parsed sysargs: args={'help': False, 'verbose': False, 'quiet': False, 'verbosity': 'trace', 'version': False, 'trace': False} filtered=[]                                                                 
2023-08-08 18:50:01.262 Using default command: 'pack'                                                                
2023-08-08 18:50:01.262 General parsed sysargs: command='pack' args=[]                                               
2023-08-08 18:50:01.265 Command parsed sysargs: Namespace(bind_ssh=False, build_for=None, debug=False, destructive_mode=False, directory=None, enable_developer_debug=False, enable_experimental_extensions=False, enable_experimental_plugins=False, enable_experimental_target_arch=False, enable_experimental_ua_services=False, enable_manifest=False, http_proxy=None, https_proxy=None, manifest_image_information=None, output=None, provider=None, target_arch=None, ua_token=None, use_lxd=False)                                                                                                   
2023-08-08 18:50:01.265 lifecycle command: 'pack', arguments: Namespace(bind_ssh=False, build_for=None, debug=False, destructive_mode=False, directory=None, enable_developer_debug=False, enable_experimental_extensions=False, enable_experimental_plugins=False, enable_experimental_target_arch=False, enable_experimental_ua_services=False, enable_manifest=False, http_proxy=None, https_proxy=None, manifest_image_information=None, output=None, provider=None, target_arch=None, ua_token=None, use_lxd=False)                                                                                     
2023-08-08 18:50:01.265 command: pack, arguments: Namespace(bind_ssh=False, build_for=None, debug=False, destructive_mode=False, directory=None, enable_developer_debug=False, enable_experimental_extensions=False, enable_experimental_plugins=False, enable_experimental_target_arch=False, enable_experimental_ua_services=False, enable_manifest=False, http_proxy=None, https_proxy=None, manifest_image_information=None, output=None, provider=None, target_arch=None, ua_token=None, use_lxd=False)                                                                                                 
2023-08-08 18:50:01.292 Created build plan:
  build-on: amd64 build-for: amd64                                       
2023-08-08 18:50:01.292 CPU count (from process affinity): 4                                                         
2023-08-08 18:50:01.292 Invalid SNAPCRAFT_MAX_PARALLEL_BUILD_COUNT ''                                                
2023-08-08 18:50:01.292 Running on amd64 for amd64                                                                   
2023-08-08 18:50:01.296 Checking build provider availability                                                         
2023-08-08 18:50:01.310 Retrieved snap config: {}                                                                    
2023-08-08 18:50:01.311 Using default provider 'lxd' on linux system.                                                
2023-08-08 18:50:01.482 Executing on host: lxc --project default profile show local:default                          
2023-08-08 18:50:01.625 Using hostname 'snapcraft-servicer-on-amd64-for-amd64-19537807'                              
2023-08-08 18:50:01.626 Launching instance...                                                                        
2023-08-08 18:50:01.626 Executing on host: lxc remote list --format=yaml                                             
2023-08-08 18:50:01.727 Remote 'craft-com.ubuntu.cloud-buildd' already exists.                                       
2023-08-08 18:50:01.728 Executing on host: lxc project list local: --format=yaml                                     
2023-08-08 18:50:01.864 Set LXD instance name to 'snapcraft-servicer-on-amd64-for-amd64-19537807'                    
2023-08-08 18:50:01.865 Checking for instance 'snapcraft-servicer-on-amd64-for-amd64-19537807' in project 'snapcraft' in remote 'local'                                                                                                    
2023-08-08 18:50:01.865 Executing on host: lxc --project snapcraft list local: --format=yaml                         
2023-08-08 18:50:02.009 Executing on host: lxc --project snapcraft config get local:snapcraft-servicer-on-amd64-for-amd64-19537807 raw.idmap                                                                                               
2023-08-08 18:50:02.141 Unexpected id map for 'snapcraft-servicer-on-amd64-for-amd64-19537807' (expected 'both 1000 0', got '').                                                                                                           
2023-08-08 18:50:02.141 Cleaning incompatible instance 'snapcraft-servicer-on-amd64-for-amd64-19537807' (reason: the instance's id map ('raw.idmap') is not configured as expected).                                                       
2023-08-08 18:50:02.142 Executing on host: lxc --project snapcraft delete local:snapcraft-servicer-on-amd64-for-amd64-19537807 --force                                                                                                     
2023-08-08 18:50:04.445 Instance 'snapcraft-servicer-on-amd64-for-amd64-19537807' does not exist.                    
2023-08-08 18:50:04.446 Set LXD instance name to 'base-instance-snapcraft-buildd-base-v10--2d55678e0339df02cd48'     
2023-08-08 18:50:04.446 Checking for base instance 'base-instance-snapcraft-buildd-base-v10--2d55678e0339df02cd48' in project 'snapcraft' in remote 'local'                                                                                
2023-08-08 18:50:04.447 Executing on host: lxc --project snapcraft list local: --format=yaml                         
2023-08-08 18:50:04.553 Base instance 'base-instance-snapcraft-buildd-base-v10--2d55678e0339df02cd48' does not exist.
2023-08-08 18:50:04.553 Creating new instance from image 'core22' from remote 'craft-com.ubuntu.cloud-buildd'.       
2023-08-08 18:50:04.554 Executing on host: lxc --project snapcraft info local:                                       
2023-08-08 18:50:04.699 Executing on host: lxc --project snapcraft launch craft-com.ubuntu.cloud-buildd:core22 local:snapcraft-servicer-on-amd64-for-amd64-19537807 --config security.syscalls.intercept.mknod=true                        
2023-08-08 18:50:11.711 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf                                                                                   
2023-08-08 18:50:11.933 Executing on host: lxc --project snapcraft file push /tmp/tmp0smvpjac local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/craft-instance.conf --mode=0644                                                     
2023-08-08 18:50:12.084 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/craft-instance.conf                                                                           
2023-08-08 18:50:12.284 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 cat /etc/os-release                                                                                                
2023-08-08 18:50:12.617 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf                                                                                   
2023-08-08 18:50:12.921 Executing on host: lxc --project snapcraft file pull local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/craft-instance.conf /home/hp/tmp5pa94zd_.tmp-craft/tmpnroxb946                                       
2023-08-08 18:50:13.138 Executing on host: lxc --project snapcraft file push /tmp/tmpmh8yli6r local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/apt/apt.conf.d/20auto-upgrades --mode=0644                                          
2023-08-08 18:50:13.248 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/apt/apt.conf.d/20auto-upgrades                                                                
2023-08-08 18:50:13.595 Executing on host: lxc --project snapcraft file push /tmp/tmp5e370iie local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/environment --mode=0644                                                             
2023-08-08 18:50:13.757 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/environment                                                                                   
2023-08-08 18:50:13.994 Waiting for environment to be ready...                                                       
2023-08-08 18:50:13.996 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl is-system-running                                                                                        
2023-08-08 18:50:14.319 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf                                                                                   
2023-08-08 18:50:14.654 Executing on host: lxc --project snapcraft file pull local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/craft-instance.conf /home/hp/tmpc6h0kk2v.tmp-craft/tmp7d21_yl9                                       
2023-08-08 18:50:14.878 Executing on host: lxc --project snapcraft file push /tmp/tmpx1tjl7ga local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/craft-instance.conf --mode=0644                                                     
2023-08-08 18:50:14.997 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/craft-instance.conf                                                                           
2023-08-08 18:50:15.197 Executing on host: lxc --project snapcraft file push /tmp/tmpsabmol69 local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/hostname --mode=0644                                                                
2023-08-08 18:50:15.336 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/hostname                                                                                      
2023-08-08 18:50:15.506 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 hostname -F /etc/hostname                                                                                          
2023-08-08 18:50:15.747 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf                                                           
2023-08-08 18:50:15.980 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl enable systemd-resolved                                                                                  
2023-08-08 18:50:16.347 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl restart systemd-resolved                                                                                 
2023-08-08 18:50:16.656 Executing on host: lxc --project snapcraft file push /tmp/tmpfke4w129 local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/systemd/network/10-eth0.network --mode=0644                                         
2023-08-08 18:50:16.777 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/systemd/network/10-eth0.network                                                               
2023-08-08 18:50:16.951 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl enable systemd-networkd                                                                                  
2023-08-08 18:50:17.319 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl restart systemd-networkd                                                                                 
2023-08-08 18:50:17.647 Waiting for networking to be ready...                                                        
2023-08-08 18:50:17.649 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 getent hosts snapcraft.io                                                                                          
2023-08-08 18:50:18.028 Executing on host: lxc --project snapcraft file push /tmp/tmpxajisu0h local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/apt/apt.conf.d/00no-recommends --mode=0644                                          
2023-08-08 18:50:18.249 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/apt/apt.conf.d/00no-recommends                                                                
2023-08-08 18:50:18.424 Executing on host: lxc --project snapcraft file push /tmp/tmpi77enwdq local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/apt/apt.conf.d/00update-errors --mode=0644                                          
2023-08-08 18:50:18.595 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /etc/apt/apt.conf.d/00update-errors                                                                
2023-08-08 18:50:18.772 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 apt-get update                                                                                                     
2023-08-08 18:50:32.605 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 apt-get install -y apt-utils curl gnupg dirmngr git                                                                
2023-08-08 18:50:48.366 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 apt-get install -y fuse udev                                                                                       
2023-08-08 18:50:57.595 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl enable systemd-udevd                                                                                     
2023-08-08 18:50:57.946 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl start systemd-udevd                                                                                      
2023-08-08 18:50:58.187 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 apt-get install -y snapd                                                                                           
2023-08-08 18:51:15.912 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl start snapd.socket                                                                                       
2023-08-08 18:51:16.179 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 systemctl restart snapd.service                                                                                    
2023-08-08 18:51:17.075 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap wait system seed.loaded                                                                                       
2023-08-08 18:51:58.129 Holding refreshes for snaps.                                                                 
2023-08-08 18:51:58.132 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap set system refresh.hold=2023-08-09T18:51:58.127424Z                                                           
2023-08-08 18:51:58.502 Waiting for pending snap refreshes to complete.                                              
2023-08-08 18:51:58.505 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap watch '--last=auto-refresh?'                                                                                  
2023-08-08 18:51:58.768 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap unset system proxy.http                                                                                       
2023-08-08 18:51:59.064 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap unset system proxy.https                                                                                      
2023-08-08 18:51:59.395 Installing snap 'snapcraft' with channel=None and classic=True                               
2023-08-08 18:51:59.396 Installing snap 'snapcraft' from host (classic=True)                                         
2023-08-08 18:51:59.407 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /etc/craft-instance.conf                                                                                   
2023-08-08 18:51:59.573 Executing on host: lxc --project snapcraft file pull local:snapcraft-servicer-on-amd64-for-amd64-19537807/etc/craft-instance.conf /home/hp/tmpn7et25av.tmp-craft/tmpix3z3s75                                       
2023-08-08 18:51:59.716 Revisions found: host='9542', target=None                                                    
2023-08-08 18:51:59.721 Creating an assert file for snap 'snapcraft'                                                 
2023-08-08 18:51:59.722 Executing command on host: ['snap', 'known', 'account-key', 'public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul']                                                                
2023-08-08 18:51:59.764 Executing command on host: ['snap', 'known', 'snap-declaration', 'snap-name=snapcraft']      
2023-08-08 18:51:59.807 Executing command on host: ['snap', 'known', 'snap-revision', 'snap-revision=9542', 'snap-id=vMTKRaLjnOJQetI78HjntT37VuoyssFE']                                                                                    
2023-08-08 18:51:59.851 Executing command on host: ['snap', 'known', 'account', 'account-id=canonical']              
2023-08-08 18:51:59.892 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -d /tmp                                                                                                       
2023-08-08 18:52:00.077 Executing on host: lxc --project snapcraft file push /home/hp/tmp2lranej5.tmp-craft/tmp3e3b1yqr local:snapcraft-servicer-on-amd64-for-amd64-19537807/tmp/snapcraft.assert --gid=0 --uid=0                          
2023-08-08 18:52:00.185 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 snap ack /tmp/snapcraft.assert                                                                                     
2023-08-08 18:52:00.687 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -d /tmp                                                                                                       
2023-08-08 18:52:00.862 Executing on host: lxc --project snapcraft file push /home/hp/tmp9ub3syu8.tmp-craft/snapcraft.snap local:snapcraft-servicer-on-amd64-for-amd64-19537807/tmp/snapcraft.snap --gid=0 --uid=0                         
2023-08-08 18:52:01.621 Executing in container: lxc --project snapcraft exec local:snapcraft-servicer-on-amd64-for-amd64-19537807 -- 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 - (41.5s)                                                               Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/actions/snap_installer.py", line 320, in inject_from_host
    executor.execute_run(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
    return self.lxc.exec(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 371, in exec
    return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
  File "/snap/snapcraft/9542/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-servicer-on-amd64-for-amd64-19537807', '--', '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 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 658, in _install_snaps
    snap_installer.inject_from_host(
  File "/snap/snapcraft/9542/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-servicer-on-amd64-for-amd64-19537807 -- 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: 1
* Command standard error output: b'error: cannot perform the following tasks:\n- Ensure prerequisites for "snapcraft" are available (cannot install snap base "core20": Post "https://api.snapcraft.io/v2/snaps/refresh": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers))\n'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 138, in launched_environment
    instance = launch(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 545, in launch
    _create_instance(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 74, in _create_instance
    base_configuration.setup(executor=instance)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 484, in setup
    self._install_snaps(executor=executor, deadline=deadline)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 664, 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/9542/bin/snapcraft", line 8, in <module>
    sys.exit(run())
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/cli.py", line 255, in run
    _run_dispatcher(dispatcher, global_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/cli.py", line 228, in _run_dispatcher
    dispatcher.run()
  File "/snap/snapcraft/9542/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/9542/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 265, in run
    super().run(parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 138, in run
    parts_lifecycle.run(self.name, parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 216, in run
    _run_command(
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 262, in _run_command
    _run_in_provider(project, command_name, parsed_args)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 556, in _run_in_provider
    with provider.launched_environment(
  File "/snap/snapcraft/9542/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/9542/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 153, in launched_environment
1 snap install /tmp/snapcraft.snap --classic \ (41.6s)                                                                   raise LXDError(str(error)) from error
craft_providers.lxd.errors.LXDError: failed to inject host's snap 'snapcraft' into target environment.

I uninstalled docker and deleted all the bridges, also reinstalled lxd but the issue persists.

Thanks!

This is an interesting error. There is network connectivity because calls like apt update and apt install are working. Perhaps it is just something to do with the snap store.

I’m assume you are able to download snaps on your host machine since you installed snapcraft today.

Let’s see what’s going on inside the container. Can you try running these commands?

lxc --project snapcraft start snapcraft-servicer-on-amd64-for-amd64-19537807
lxc --project snapcraft exec snapcraft-servicer-on-amd64-for-amd64-19537807 -- curl -v -D- https://api.snapcraft.io
lxc --project snapcraft exec snapcraft-servicer-on-amd64-for-amd64-19537807 -- snap install core20

Resolved. The commands were giving an error Error: The instance is already running but worked on reboot. Perhaps the effect of docker removal kicked in after reboot.

I’ll re-install docker to see whether the problem recurs.

Great! Glad a reboot did the trick. There is some more details on LXD + Docker compatibility here: https://documentation.ubuntu.com/lxd/en/latest/howto/network_bridge_firewalld/#prevent-connectivity-issues-with-lxd-and-docker