Snapcraft build is constantly failing because of connection issue

I have been experiencing a issue with building snaps over the past week. I have tried different networks but they all seem to have the same issues. I would say about 9 out of 10 build I experience a connection issue shown bellow. I know that when building the snap it is launching a VM so not sure if there is an issue with it or something else. Is anyone experiencing similar issue and found a solution?

Err libgdbm5_1.14.1-6_amd64.deb                                                                                                                                                                       
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
Fetched 0 B in 6s (0 B/s)                                                                                                                                                                             
Package fetch error: The item '/root/.cache/snapcraft/download/libgdbm5_1.14.1-6_amd64.deb' could not be fetched: Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out

Same here:

$ snapcraft
Launching a VM.
Launched: snapcraft-darktable                                                   
Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease                         
  Could not connect to archive.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142). - connect (111: Connection refused) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
Err:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
Err:3 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Could not connect to security.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.38). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.39). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.142). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
Reading package lists... Done         
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Could not connect to security.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.38). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.91.39). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.142). - connect (111: Connection refused) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Could not connect to archive.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.142). - connect (111: Connection refused) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::23). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::15). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::24). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1562::18). - connect (101: Network is unreachable)
W: Some index files failed to download. They have been ignored, or old ones used instead.

I can duplicate those results consistently, and my internet is working fine. Note that --use-lxd also works fine. I seem to have an ipv6 address, do you @Levi-Armstrong?

@kyrofa this might be worthy of a multipass issue on github, thoughts @Saviq?

Well… This, and the fact that this is happening randomly, suggests it’s an actual network issue. We’re not setting up IPv6 NATing, so Network unreachable on that is expected. That in itself may warrant a Multipass bug, but us moving to LXD as the backend would move the onus of that on LXD (or rather, the user, to configure IPv6 in LXD).

Why would @Levi-Armstrong’s setup (sometimes) only reach out on IPv6 and skip v4, I couldn’t say off the top of my head, would be interesting to get info on how the network is set up in the instance in that case, or at least get logs out of Multipass (accessing logs).

I switched to --use-lxd and I am now able create my snap now. I am unable to post the logs on a public forum, but I have provided them to @kyrofa via email.

I’ve been bumping into the issue for a while, even when using --use-lxd. I am able to get a working build system using Multipass by using the script posted by @townsend in this issue: