MySQL option MYSQL_OPT_CONNECT_TIMEOUT ignored
-
The Qt docs (http://doc.qt.io/qt-5/qsqldatabase.html#setConnectOptions) states that the mysql driver accepts the MYSQL_OPT_CONNECT_TIMEOUT option. However it seems to be ignored, and the timeout seems to be about 20-25 seconds when the network is unreachable, independently of what is set with the option.
QString dbName = "mydb"; { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", dbName); db.setHostName(databaseUrl); db.setPort(databasePort); db.setDatabaseName(databaseName); db.setUserName(databaseUsername); db.setPassword(databasePassword); db.setConnectOptions("MYSQL_OPT_CONNECT_TIMEOUT=5"); if(db.open() == false) qDebug("Cannot access database"); else { QSqlQuery query = QSqlQuery(db); ... } }
This code blocks in open() for about 20-25 seconds instead of 5. I tried it with Qt 5.5.0 with the patched (https://codereview.qt-project.org/#/c/123488/) mysql plugin in both windows and linux. In windows I had trouble using the mysql library, so I used mariadb instead, but in linux I used the mysql lib, and both seems to ignore the timeout option.
-
Hi,
What MYSQL_VERSION_ID do you have with mariadb ?
-
So since you already applied the patch, I'd recommend checking the return value of mysql_options call that sets the timeout to ensure you don't have anything funky going on there.
-
mysql_options called with MYSQL_OPT_CONNECT_TIMEOUT returns 0 (success) both for mysql and mariadb libraries.