Debian

Debian Stretch 的段錯誤

  • May 31, 2020

段錯誤,但為什麼?它只發生在 debian:stretch+mysql.connector+tox 和 Python3.x 上。只需幾行即可重現:

FROM debian:stretch
RUN apt update -y && apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev gcc wget tox vim python-pip python3-pip
RUN wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
RUN tar xvf Python-3.6.9.tgz && cd Python-3.6.9 &&./configure --enable-optimizations --enable-shared --with-ssl --with-ensurepip=install && make -j8 && make altinstall
RUN mkdir /tox-test && echo "[tox]" >> /tox-test/tox.ini && echo "envlist = py36" >> /tox-test/tox.ini && echo "[testenv]" >> /tox-test/tox.ini && echo "deps=" >> /tox-test/tox.ini
RUN echo "  mysql-connector-python" >> /tox-test/tox.ini && echo "commands=python3.6 setup.py test" >> /tox-test/tox.ini
RUN mkdir /tox-test/tests && touch /tox-test/tests/__init__.py && echo "import faulthandler\nfaulthandler.enable()\nimport mysql.connector as mysql" >> /tox-test/tests/test_segfault.py
RUN echo "mysql.connect(host='localhost', user='joe', password='bloggs')" >> /tox-test/tests/test_segfault.py
RUN mkdir /tox-test/foo && echo "print('foo')" >> /tox-test/foo/foo.py
RUN echo "from setuptools import setup" >> /tox-test/setup.py && echo "setup( name='foo',version='1.0',description='A module',author='Niklas R.',author_email='foomail@foo.com',packages=['foo'],test_suite='tests',)" >> /tox-test/setup.py
RUN cd /tox-test && export LD_LIBRARY_PATH=/Python-3.6.9 && tox

上面會產生一個段錯誤。使用 Ubuntu 和 Debian Jessie,它可以工作或可以解決。我不明白為什麼 Stretch 會發生這種情況,我無法修復它。段錯誤似乎與網路有關,因為如果我寫“127.0.0.1”而不是“localhost”,那麼它不會崩潰。請幫我理解。我的猜測是進口正在遮蔽或使用一些自己的 ssl 版本或類似版本。這是相當牽強的。它在 Ubuntu 上也可以重現,甚至更奇怪的故事是,在 Ubuntu 上,如果我從不使用導入添加到 python 中,段錯誤是固定werkzeug.exceptions import BadRequestKeyError的,只在不使用它的情況下導入它。如果我用 PyMySQL 替換 mysql-connector-python ,那麼它可以工作。所以它一定是來自 mysql-connector-python 的東西。關於該連接器有類似的錯誤報告:https://bugs.mysql.com/bug.php?id=97220

如果我更改一個字元串“localhost”並改為“127.0.0.1”,則不再有段錯誤:

FROM debian:stretch
RUN apt update -y && apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev gcc wget tox vim python-pip python3-pip
RUN wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
RUN tar xvf Python-3.6.9.tgz && cd Python-3.6.9 &&./configure --enable-optimizations --enable-shared --with-ssl --with-ensurepip=install && make -j8 && make altinstall
RUN mkdir /tox-test && echo "[tox]" >> /tox-test/tox.ini && echo "envlist = py36" >> /tox-test/tox.ini && echo "[testenv]" >> /tox-test/tox.ini && echo "deps=" >> /tox-test/tox.ini
RUN echo "  mysql-connector-python" >> /tox-test/tox.ini && echo "commands=python3.6 setup.py test" >> /tox-test/tox.ini
RUN mkdir /tox-test/tests && touch /tox-test/tests/__init__.py && echo "import faulthandler\nfaulthandler.enable()\nimport mysql.connector as mysql" >> /tox-test/tests/test_segfault.py
RUN echo "mysql.connect(host='127.0.0.1', user='joe', password='bloggs')" >> /tox-test/tests/test_segfault.py
RUN mkdir /tox-test/foo && echo "print('foo')" >> /tox-test/foo/foo.py
RUN echo "from setuptools import setup" >> /tox-test/setup.py && echo "setup( name='foo',version='1.0',description='A module',author='Niklas R.',author_email='foomail@foo.com',packages=['foo'],test_suite='tests',)" >> /tox-test/setup.py
RUN cd /tox-test && export LD_LIBRARY_PATH=/Python-3.6.9 && tox

起初,它看起來像一個套接字問題,但 socket.gethostbyname(host_name) 有效。經過一番探勘,我發現如果您在 tox.ini 中將其更改為“mysql-connector-python-rf”,則該問題與“mysql-connector-python”無關,錯誤就消失了。這意味著在 mysql-connector-python 的某個地方它無法將 dns 解析為 ip。

引用自:https://unix.stackexchange.com/questions/590086