chroot 中的 Pip SSLError malloc 失败

Pip SSLError malloc failure in chroot

我安装了一个基于 debian (linaro) 的 rootfs.img.raw 从稀疏映像(使用 simg2img)和 运行 chroot 创建的

$ sudo chroot /mnt/intrinsycimg qemu-aarch64-static /bin/bash

使用 qemu 模拟 ARM64。我的 qemu-aarch64 版本是 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.26).

在 python(版本 3.7.3)上使用 pip(版本 18.1)我试图用它安装一个 运行dom 包,但出现以下错误:

root@user:/home/linaro# pip3 install --user progress
qemu: Unsupported syscall: 278
Collecting progress
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Could not find a version that satisfies the requirement progress (from versions: )
No matching distribution found for progress

我尝试按照此 github issue answer 添加 --trusted-host 标志,但出现 malloc 失败:

root@user:/home/linaro# pip3 install progress --trusted-host pypi.org --trusted-host files.pythonhosted.org
qemu: Unsupported syscall: 278
Collecting progress
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))': /simple/progress/
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
  Could not fetch URL https://pypi.org/simple/progress/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/progress/ (Caused by SSLError(SSLError(336236609, '[SSL] malloc failure (_ssl.c:2994)'))) - skipping
  Could not find a version that satisfies the requirement progress (from versions: )
No matching distribution found for progress

我还尝试将 /run/dev/sys/proc(例如 sudo mount --rbind /run/ /mnt/linaroimg/run/)挂载为 this user suggested,但我得到相同的结果。

我的 openssl 版本是 OpenSSL 1.1.1d,我发现了一个关于 malloc failure for 1.1.1d 的问题,所以如果我 运行 相同的命令,我会得到同样的错误:

root@user:/home/linaro# python3 -c 'import urllib.request; urllib.request.urlopen("https://pypi.org")'
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
qemu: Unsupported syscall: 278
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.7/urllib/request.py", line 1285, in do_open
    h = http_class(host, timeout=req.timeout, **http_conn_args)
  File "/usr/lib/python3.7/http/client.py", line 1383, in __init__
    context = ssl._create_default_https_context()
  File "/usr/lib/python3.7/ssl.py", line 565, in create_default_context
    context = SSLContext(PROTOCOL_TLS)
  File "/usr/lib/python3.7/ssl.py", line 388, in __new__
    self = _SSLContext.__new__(cls, protocol)
ssl.SSLError: [SSL] malloc failure (_ssl.c:2994)

我尝试手动编译 OpenSSL_1_1_1g 版本:

root@user:/home/linaro# openssl version
OpenSSL 1.1.1g  21 Apr 2020 (Library: OpenSSL 1.1.1d  10 Sep 2019)

但最终结果相同。我怀疑 Library: OpenSSL 1.1.1d,但我 git 克隆了 openssl 存储库并检查了 OpenSSL_1.1.1g 标签。另外我想避免自己编译 openssl,因为我更喜欢稍后通过 apt 更新它。

我应该如何解决这个问题?

这里的问题是您使用的是旧版本的 QEMU,它在 linux 用户模式支持中存在已知错误(多线程来宾程序尤其存在问题)。尝试更新的版本,例如 QEMU 5.0 应该会导致错误消失。