Driver QMysql can't be loaded

Bug #1889851 reported by Olivier Subilia
272
This bug affects 3 people
Affects Status Importance Assigned to Milestone
mysql-8.0 (Ubuntu)
Fix Released
High
Marc Deslauriers
Focal
Fix Released
High
Marc Deslauriers
Groovy
Fix Released
High
Marc Deslauriers

Bug Description

The faulty package is libmysqlclient21, installed automatically
(http://ch.archive.ubuntu.com/ubuntu focal/main amd64)
but launchpad complains about "libmysqlclient" does not exist in Ubuntu...

I Use a programm writen in python / PyQt5 to access a mysql database, which has always functioned.
Since upgrade to libmysqlclient21 8.0.21-0ubuntu0.20.04.3, I have a continual "Database Error:Driver not loaded Driver not loaded" "QMYSQL driver not loaded"
Reinstalling libmysqlclient21 8.0.19-0ubuntu5 (which worked before) solved the problem.
I suppose it's a regression bug

Ubuntu version: Ubuntu 20.04.1 LTS

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. It seems that your bug report is not filed about a specific source package though, rather it is just filed against Ubuntu in general. It is important that bug reports be filed about source packages so that people interested in the package can find the bugs about it. You can find some hints about determining what package your bug might be about at https://wiki.ubuntu.com/Bugs/FindRightPackage. You might also ask for help in the #ubuntu-bugs irc channel on Freenode.

To change the source package that this bug is filed about visit https://bugs.launchpad.net/ubuntu/+bug/1889851/+editstatus and add the package name in the text box next to the word Package.

[This is an automated message. I apologize if it reached you inappropriately; please just reply to this message indicating so.]

tags: added: bot-comment
affects: ubuntu → mysql-8.0 (Ubuntu)
Revision history for this message
Olivier Subilia (osubillia) wrote :

Sorry. I've just understood the difference between source package and installed package name (I should use apt show more often...)

Completely minimal example:

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSql import QSqlDatabase

app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase("QMYSQL")

with libmysqlclient21=8.0.19-0ubuntu5:
(OK)
with libmysqlclient21=8.0.21-0ubuntu0.20.04.3:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Hi Olivier,
thanks for the report - I can confirm that this triggers the issue:

$ apt install python3-pyqt5 python3-pyqt5.qtsql libqt5sql5-mysql
$ cat > test.py << EOF
#!/usr/bin/python3

# -*- coding: utf-8 -*-

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtSql import QSqlDatabase

app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase("QMYSQL")
EOF
$ python3 test.py

And also that I can switch in/out of the behavior between versions 8.0.21-0ubuntu0.20.04.3 / 8.0.19-0ubuntu5 of libmysqlclient21.

Changed in mysql-8.0 (Ubuntu):
status: New → Confirmed
importance: Undecided → High
tags: added: server-next
tags: added: regression-update
information type: Public → Public Security
Revision history for this message
Lars Tangvald (lars-tangvald) wrote :

Thanks for the report and test case! I'll test it, and pass it on upstream.

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

I think this may be related:

$ readelf --dynamic libmysqlclient.so.21.1.19 | grep BIND
 0x000000000000001e (FLAGS) BIND_NOW

$ readelf --dynamic libmysqlclient.so.21.1.21 | grep BIND
 0x000000000000001e (FLAGS) BIND_NOW STATIC_TLS

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :
Revision history for this message
Lars Tangvald (lars-tangvald) wrote :

Verified with upstream packages as well. The test case also works as expected with 8.0.20, so it was introduced in 8.0.21.

I'll do a test build to see if reverting that commit fixes it. Thanks for the tip, Marc :)

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

As loaded by python:
0x00007ffff2dd4460 0x00007ffff2e0304e Yes (*) /lib/x86_64-linux-gnu/libQt5Sql.so.5

I was trying to get a different POV on the same lib, removing python out of the picture.

Install mysql and create a DB.

$ apt install mysql-server
$ systemctl start mysql
$ systemctl status mysql
$ mysql -u root
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';
mysql> CREATE DATABASE test;
mysql> GRANT ALL PRIVILEGES ON test.* TO 'newuser'@'localhost';
mysql> USE test;
mysql> CREATE TABLE testtable (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY);

Test Program:

# cat mysqlqt.pro
######################################################################
# Automatically generated by qmake (3.1) Tue Aug 4 12:46:45 2020
######################################################################

TEMPLATE = app
TARGET = mysqlqt
INCLUDEPATH += .
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtCore
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtGui
INCLUDEPATH += /usr/include/x86_64-linux-gnu/qt5/QtWidgets

QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

# The following define makes your compiler warn you if you use any
# feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

# Input
SOURCES += mysqlqt.cpp

# cat mysqlqt.cpp
#include <QApplication>
#include <QPushButton>
#include <QSqlDatabase>

int main()
{
    QStringList drivers = QSqlDatabase::drivers();
    for(int i=0 ; i < drivers.length() ; i++) {
        qDebug("driver: %s", qUtf8Printable(drivers[i]));
    }

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("test");
    db.setUserName("newuser");
    db.setPassword("user_password");
    bool ok = db.open();

    qDebug("ok %i isopen %i isvalid %i", ok, db.isOpen(), db.isValid());
    qDebug("db-driver %s", qUtf8Printable(db.driverName()));

    qDebug("# start tables");
    QStringList tables = db.tables();
    for(int i=0 ; i < tables.length() ; i++) {
        qDebug("table: %s", qUtf8Printable(tables[i]));
    }
    qDebug("# end tables");

    return ok;
}

$ ./mysqlqt
driver: QSQLITE
driver: QMYSQL
driver: QMYSQL3
ok 1 isopen 1 isvalid 1
db-driver QMYSQL
# start tables
table: testtable
# end tables

So the QMYSQL isn't generally disfunctional since this update, it must be related to something more specific in the python wrapping of it.

Revision history for this message
Lars Tangvald (lars-tangvald) wrote :

Verified that reverting the commit Marc suggested makes the test case pass.

If I understand it correctly, STATIC_TLS is a limited resource, so if the python wrapping loads other libraries that also use it, but your c program doesn't?

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

Lars, I think that is what is happening, yes.

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

(See bug 1890170 for another reproducer)

Changed in mysql-8.0 (Ubuntu Focal):
importance: Undecided → High
assignee: nobody → Marc Deslauriers (mdeslaur)
Changed in mysql-8.0 (Ubuntu Groovy):
assignee: nobody → Marc Deslauriers (mdeslaur)
Changed in mysql-8.0 (Ubuntu Focal):
status: New → Confirmed
Revision history for this message
Lars Tangvald (lars-tangvald) wrote :

A simpler fix is to add a cmake flag to override the tls-model flag:

-DCMAKE_CXX_FLAGS="-ftls-model=global-dynamic" \

to debian/rules

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package mysql-8.0 - 8.0.21-0ubuntu0.20.04.4

---------------
mysql-8.0 (8.0.21-0ubuntu0.20.04.4) focal-security; urgency=medium

  * SECURITY REGRESSION: libmysqlclient loading issues (LP: #1889851)
    - debian/patches/revert_faster_tls_model.patch: revert an upstream
      commit that switches the tls-model to initial-exec. This is causing
      "cannot allocate memory in static TLS block" errors when attempting
      to load the library in certain scenarios.

 -- Marc Deslauriers <email address hidden> Tue, 04 Aug 2020 07:39:21 -0400

Changed in mysql-8.0 (Ubuntu Focal):
status: Confirmed → Fix Released
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package mysql-8.0 - 8.0.21-0ubuntu4

---------------
mysql-8.0 (8.0.21-0ubuntu4) groovy; urgency=medium

  * SECURITY REGRESSION: libmysqlclient loading issues (LP: #1889851)
    - debian/patches/revert_faster_tls_model.patch: revert an upstream
      commit that switches the tls-model to initial-exec. This is causing
      "cannot allocate memory in static TLS block" errors when attempting
      to load the library in certain scenarios.

 -- Marc Deslauriers <email address hidden> Tue, 04 Aug 2020 07:39:21 -0400

Changed in mysql-8.0 (Ubuntu Groovy):
status: Confirmed → Fix Released
Revision history for this message
Jose (jortuno) wrote :

I would like to report the same problem happening again with the latest version of libmysqlclient21.
I am speaking about this bug:
https://stackoverflow.com/questions/63307453/cannot-allocate-memory-in-static-tls-block-in-a-python-flask-application

Which again was solved downgrading to the previous version: 8.0.28-0ubuntu0.20.04.3

Thanks :)

Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

8.0.28-0ubuntu0.20.04.3 is the current version, and it still contains the patch for this issue.

What version did you install that triggered the issue, and where did you get it?

To post a comment you must log in.
This report contains Public Security information  
Everyone can see this security related information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.