Bug #104860 import numpy before mysql.connector, connect will Segmentation Fault
Submitted: 7 Sep 2021 17:59 Modified: 3 May 2022 21:49
Reporter: john grabner Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:8.0.26 OS:Any
Assigned to: CPU Architecture:Any

[7 Sep 2021 17:59] john grabner
Description:
Dockerfile
   FROM ubuntu:18.04

   RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update && apt-get install -y python3.8 python3.8-dev python3-pip

   RUN ln -sfn /usr/bin/python3.8 /usr/bin/python3 && ln -sfn /usr/bin/python3 /usr/bin/python && ln -sfn /usr/bin/pip3 /usr/bin/pip

   RUN pip install mysql-connector-python==8.0.26

   RUN pip install --user numpy

   WORKDIR /app
   COPY . .

   CMD python ./crash.py

crash.py file
   import time
   import numpy as np
   import mysql.connector

   cnx = mysql.connector.connect( user='root', password='xxxxx', host='xxxx',  port=3306, database='xxxxx')

   cursor = cnx.cursor()
   q = "SELECT group_id FROM ancient_script_db.group LIMIT 0,1"

   while True:
    
    cursor.execute(q)

    for c in cursor:
        print(c, flush=True)

    time.sleep(1)

The above will seg fault at line cnx = mysql.connector.connect. Reverse order of import and program runs correctly.

How to repeat:

Create the above 2 demonstration file and run in docker to demonstrate, replacing xxx with your own db.

Observer segmentation fault

   image_worker_1      | Segmentation fault (core dumped)
   help-me-trancribe-dev_image_worker_1 exited with code 139

reverse order of import numpy as np and import mysql.connector
and code runs correctly.

   image_worker_1      | (1,)
   image_worker_1      | (1,)
   image_worker_1      | (1,)
   image_worker_1      | (1,)
   image_worker_1      | (1,)

BTW, Numpy is a popular library for numeric processing.
[7 Sep 2021 18:05] john grabner
changed 
   RUN pip install --user numpy
to
   RUN pip install numpy

No impact, Seg fault occurs as described.
[7 Sep 2021 18:25] john grabner
Bug reproduced in 
   RUN pip install mysql-connector-python==8.0.20
   RUN pip install mysql-connector-python==8.0.21
   RUN pip install mysql-connector-python==8.0.22
   RUN pip install mysql-connector-python==8.0.26

Bug not present in
   RUN pip install mysql-connector-python==8.0.19
   RUN pip install mysql-connector-python==8.0.18
   RUN pip install mysql-connector-python==8.0.16
   RUN pip install mysql-connector-python==8.0.5

Some other bug present in the release that causes a program crash but not segment fault
   RUN pip install mysql-connector-python==8.0.17

# image_worker_1      | Traceback (most recent call last):
# image_worker_1      |   File "./crash.py", line 15, in <module>
# image_worker_1      |     cnx = mysql.connector.connect( user='root', password='108885', host='mysql-ancient-db',  port=3306, database='ancient_script_db')
# image_worker_1      |   File "/usr/local/lib/python3.8/dist-packages/mysql/connector/__init__.py", line 173, in connect
# image_worker_1      |     return MySQLConnection(*args, **kwargs)
# image_worker_1      |   File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection.py", line 104, in __init__
# image_worker_1      |     self.connect(**kwargs)
# image_worker_1      |   File "/usr/local/lib/python3.8/dist-packages/mysql/connector/abstracts.py", line 777, in connect
# image_worker_1      |     self.config(**kwargs)
# image_worker_1      |   File "/usr/local/lib/python3.8/dist-packages/mysql/connector/abstracts.py", line 404, in config
# image_worker_1      |     self._add_default_conn_attrs()
# image_worker_1      |   File "/usr/local/lib/python3.8/dist-packages/mysql/connector/connection.py", line 126, in _add_default_conn_attrs
# image_worker_1      |     os_ver = "-".join(platform.linux_distribution()[0:2]) # pylint: disable=W1505
# image_worker_1      | AttributeError: module 'platform' has no attribute 'linux_distribution'
[9 Sep 2021 8:15] MySQL Verification Team
Hello john grabner,

Thank you for the report and test case.

regards,
Umesh
[21 Oct 2021 9:05] Nuno Mariz
Posted by developer:
 
Thanks for reporting it. This is a duplicate of BUG#30429284.