php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76525 mysqli::commit does not throw if MYSQLI_REPORT_ERROR enabled and mysqlnd used
Submitted: 2018-06-25 08:35 UTC Modified: 2020-10-28 12:01 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: willem at mollie dot nl Assigned: nikic (profile)
Status: Closed Package: MySQLi related
PHP Version: 7.1.19 OS: Debian
Private report: No CVE-ID: None
 [2018-06-25 08:35 UTC] willem at mollie dot nl
Description:
------------
We experienced lost data because the mysqli::commit() function does not throw under some conditions if mysqlnd is used. We configured mysqli to use report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT.

We use a MySQL Galera cluster setup and during reboots of nodes deadlocks in the commit query can occur.

However, these deadlocks do not cause an exception to be thrown if the ::commit() method is used. Instead, false is returned. In practice, the call fails silently. 

Sending COMMIT queries manually works as expected (an exception is thrown on a dead lock).

You can see in https://github.com/php/php-src/blob/5f54f48024783df739dd5bbec64cb74063fefa06/ext/mysqli/mysqli_api.c#L741 that the error handling is missing for mysqlnd if you compare to https://github.com/php/php-src/blob/5f54f48024783df739dd5bbec64cb74063fefa06/ext/mysqli/mysqli_api.c#L1579. I'd guess that the MYSQLI_REPORT_MYSQL_ERROR macro is missing. 






Expected result:
----------------
If the commit() method encounters a "Deadlock found when trying to get lock; try restarting transaction" error (1213 code), with report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT we expect it to throw mysqli_sql_exception.

Actual result:
--------------
False is returned, e.g. the report_mode is ignored. 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-13 16:01 UTC] dominik dot fiser at w3w dot cz
We have similar and probably related problem with Galera and mysql PDO.
Galera Cluster instead of standard MySQL/MariaDD could fail on commit query due to its replication mechanism (described e.g. at https://www.percona.com/blog/2012/11/20/understanding-multi-node-writing-conflict-metrics-in-percona-xtradb-cluster-and-galera/).
We are using PPH 7.2.11 and mysql PDO with error mode PDO::ATTR_ERRMODE = PDO::ERRMODE_EXCEPTION.
That's really pain and very hard to find, if you are catching exceptions and there is no exception, no error and transaction is not commited in database. This should be fixed ASAP.
 [2018-12-13 16:22 UTC] willem at mollie dot nl
Dominik, we fixed it by switching to using a COMMIT query instead of the method.
 [2020-10-28 08:59 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2020-10-28 10:39 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2020-10-28 12:01 UTC] willem at mollie dot nl
Cheers it is marvellously appreciated.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC