BSI error: "socket.gaierror: [Errno -2] Name or service not known"

(This is a issue relating to how to use snapcraft. I did not find find a BSI category. The solution could be to fix the snapcraft.yaml in some way.)

I am trying to build on BSI.

The package, radare2, requires a very recent version of meson that even Ubuntu 18.04 does not have. I resort to the following workaround. That is, I get snapcraft to do a sudo -H pip3 install --system meson to install the freshest meson.

    source-tag: '2.6.0'
    plugin: meson
    meson-parameters: [--prefix=/usr]
    override-build: |
      sudo -H pip3 install --system meson
      snapcraftctl build
- python3-pip

I get the following error on the build server (BSI):

Running build phase...
Skipping pull radare2 (already ran)
Preparing to build radare2 
Building radare2 
Collecting meson
Traceback (most recent call last):
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 137, in _new_conn
    (, self.port), self.timeout, **extra_kw)
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/", line 67, in create_connection
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
  File "/usr/lib/python3.5/", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 560, in urlopen
    body=body, headers=headers)
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 346, in _make_request
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 787, in _validate_conn
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 217, in connect
    conn = self._new_conn()
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/", line 146, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
requests.packages.urllib3.exceptions.NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f352f8ce470>: Failed to establish a new connection: [Errno -2] Name or service not known

Is this an issue with BSI or an issue with me doing a sudo -H pip3 install --system meson?

A general rule is never use sudo in your snapcraft.yaml. Instead use a build locally that runs as root via LXD with either SNAPCRAFT_BUILD_ENVIRONMENT=lxd environment variable set or using snapcraft cleanbuild. This way you can be more confident that your local build is more consistent with that of the build service.

1 Like

Thanks for the reply!

Locally, I run snapcraft in LXD containers that I launch specifically for the snap I am developing. Sort of like snapcraft cleanbuild/SNAPCRAFT_BUILD_ENVIRONMENT=lxd but I do this in a manual way. In that respect, I am not affected by the side-effects of sudo pip3 install --system.

meson is a build environment, and to use the very new version that the package radare2 requires, I need to install that new version system-wide. Then, the meson snapcraft plugin is able to work, invoke the very fresh meson executable and perform the compilation.

Is there a way to create a part for the new version of meson, have that part execute first, and then have the meson plugin work using that freshly created meson? My attempts on this where not successful.

If your build needs root privileges then you should run sudo snapcraft, rather than putting sudo lines in your snapcraft.yaml. The build service runs as root with specific environment variables set, which get nuked when you try to run sudo foo, causing the problem you see above. As I said in my first reply, the general rule is never use sudo in your yaml.

Thanks, I made the change and it now works,