Snapcraft Network Error (seemingly with all Core22)

Hey All,

I’m just starting out with Snapcraft and am unfortunately encountering a seemingly simple issue that I’m having problems resolving. To get started, I’ve begun experimenting with some tutorials laid out in the documentation. In particular, I’m starting with the ROS2 example (https://snapcraft.io/docs/ros2-applications). Every time I try to build the snap, I get this error:

  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 617, in _setup_apt
    _execute_run(executor, ["apt-get", "update"], verify_network=True)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 135, in _execute_run
    raise NetworkError() from exc

Now an important note is I’m only encountering this error with Core22 variation of this snap. I tested the core20 release and that seems to work fine (ignoring the gpg keyserver error I see but that is a separate problem). I also tested the DOSbox example which uses Core18 and that was able to successfully generate a snap.

Curious to know if anyone has any idea what is causing this or if anyone has a solution? I am on snapcraft 7.3.1 for reference. Also, here is the full stack trace:

xps:~/ros2-talker-listener-core22$ snapcraft
Launching instance... | (48.3s)                                                                                                                                            Traceback (most recent call last):
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 130, in _execute_run
    proc = executor.execute_run(
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/lxd/lxd_instance.py", line 289, in execute_run
    return self.lxc.exec(
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/lxd/lxc.py", line 410, in exec
    return runner(final_cmd, **kwargs)  # pylint: disable=subprocess-run-check
  File "/snap/snapcraft/8931/usr/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-ros2-talker-listener-on-amd64-for-amd64-28385441', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'SNAPCRAFT_MANAGED_MODE=1', 'apt-get', 'update']' returned non-zero exit status 100.

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

Traceback (most recent call last):
  File "/snap/snapcraft/8931/bin/snapcraft", line 8, in <module>
    sys.exit(run())
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/cli.py", line 243, in run
    _run_dispatcher(dispatcher)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/cli.py", line 219, in _run_dispatcher
    dispatcher.run()
  File "/snap/snapcraft/8931/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/8931/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 259, in run
    super().run(parsed_args)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/commands/lifecycle.py", line 132, in run
    parts_lifecycle.run(self.name, parsed_args)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 215, in run
    _run_command(
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 256, in _run_command
    _run_in_provider(project, command_name, parsed_args)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/snapcraft/parts/lifecycle.py", line 540, in _run_in_provider
    with provider.launched_environment(
  File "/snap/snapcraft/8931/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/lxd/lxd_provider.py", line 126, in launched_environment
    instance = launch(
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 524, in launch
    _create_instance(
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/lxd/launcher.py", line 74, in _create_instance
    base_configuration.setup(executor=instance)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 410, in setup
    self._setup_apt(executor=executor, deadline=deadline)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 617, in _setup_apt
    _execute_run(executor, ["apt-get", "update"], verify_network=True)
  File "/snap/snapcraft/8931/lib/python3.8/site-packages/craft_providers/bases/buildd.py", line 135, in _execute_run
    raise NetworkError() from exc
craft_providers.bases.errors.NetworkError: A network related operation failed in a context of no network access.
Verify that the environment has internet connectivity; see https://craft-providers.readthedocs.io/ for further reference.
1 Like

Hi @Seiwert, welcome!

Exit code 100 from apt-get update is a challenging error to track down. I couldn’t reproduce it.
Often these networking errors are caused by Docker interfering with the IP tables on your host machine. There is some information available here: https://discourse.charmhub.io/t/charmcraft-failing-to-pack-because-of-apt-update-failure/5139

For error code 100, it could be something transient. Try running snapcraft clean; perhaps apt got in a bad state.

On a side note, I created an issue to make the error output more useful.

I’m having exact the same issue, but the ROS2 example builds if I a bypass the lxd stuff with

sudo snapcraft --destructive-mode --enable-experimental-extensions

but I this might not be a good solution, because then changes are made to my system are made. I’m running snapcraft 7.3.1 in 22.04.2 LTS inside a Virtual Box with bridged network, so network issue may not be the root cause. :frowning:

i my case it really seems that the lxd setup is incorrectly done, but I did exact the step from the ros humble tutorial.

Also a very basis hello snap fails with same, why this snap needs to install git is mystery to me but if fails the same way as the ROS2 example for canonical webpage:

subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-hello-snap-on-amd64-for-amd64-788796', '-

-', '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']' returned non-zero exit status 100.

---
name: hello-snap
version: '0.1'
summary: Greeter snap to write a "Hello"
description: |
  This example wrtites hello with bash.

base: core22
confinement: strict

apps:
  hello:
command: /bin/bash /opt/hello.bash
plugs: [network, network-bind]

parts:
  scripts:
plugin: dump
stage-packages:
  - bash
source: ./
organize:
  hello.bash: /opt/

Long Story shot, How to setup LXD corretly for snapcraft?

sudo snap install lxd
sudo lxd init --minimal

seems not to be the right way to go

Exit code 100 from apt-get update

as a workaround on some freshly installed system I got rid of this error by switching network on host system from nat to not-nat configuratiuon, it didn’t work via lxc nat + host system nat for some not totally clear reason

I know it is a bit of an old thread, but is there any chance you also have Docker installed? It installs some firewall rules that interfere with LXD’s networking. There’s some details here:

https://documentation.ubuntu.com/lxd/en/latest/howto/network_bridge_firewalld/#prevent-connectivity-issues-with-lxd-and-docker

1 Like

I have just been bitten by this (again) and it is (again) down to docker.io being installed.

It would be lovely if we could signpost this on the snapcraft side.

2 Likes

It’s a great idea and long overdue. I created an issue for documentation here so we can prioritize it

1 Like