Bug #80260 [Opn]: PDO::inTransaction() returns false when inside transaction
| From: | nikic@php.net | Date: | Tue, 20 Oct 2020 08:44:02 +0000 |
| Subject: | Bug #80260 [Opn]: PDO::inTransaction() returns false when inside transaction | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-229774@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80260&edit=1
ID: 80260
Updated by: nikic@php.net
Reported by: corey dot taylor dot fl at gmail dot com
Summary: PDO::inTransaction() returns false when inside
transaction
Status: Open
Type: Bug
Package: PDO MySQL
PHP Version: 8.0.0RC2
Block user comment: N
Private report: N
New Comment:
Okay, next guess: You are running a DDL query inside a transaction, which (for MySQL) will cause an
automatic commit, even outside autocommit mode
(https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html). That means inTransaction() reports
false, but PDO still thinks its inside a transaction.
Does that sound plausible?
Previous Comments:
------------------------------------------------------------------------
[2020-10-20 08:40:02] nikic@php.net
Do you mix usage of PDO transaction APIs with transaction queries? Like, call
PDO::beginTransaction() and then issue a manual COMMIT?
PDO's internal state could go out of sync in such a case. We should probably make PDO
internally use the same mechanism as PDO::inTransaction() to determine whether it is inside a
transaction.
However, I'm not sure this is really the case you're seeing, I suspect that is another
problem here.
------------------------------------------------------------------------
[2020-10-20 03:58:18] corey dot taylor dot fl at gmail dot com
The environment we see this on is ubuntu 16.04 (xenial) travis-ci with default mysql 5.7 and php
nightly builds. There are no custom pdo configurations.
------------------------------------------------------------------------
[2020-10-20 03:36:46] corey dot taylor dot fl at gmail dot com
Description:
------------
We started seeing failures with php 8 and mysql 5.7 that seem to suggest PDO::inTransaction() is
returning false when inside a transaction.
When calling PDO::beginTransaction(), sometimes we see this error:
PDOException: There is already an active transaction
This happens because we skip calling PDO::commit() if PDO::inTransaction() returns false. When
skipping this check and calling commit(), the transaction succeeds. Normally, when that check
returns false, commit() will fail.
I see that inTransaction() for mysql was re-written recently in this commit:
https://github.com/php/php-src/commit/6a4eeb1c47c46d8f6a1c43eb7de8e6ee8158ec99
We're not sure how to find the root cause of this. The test case in the commit checks all ways
to manually start/stop a transaction, but we obviously have other queries in the transaction.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80260&edit=1