facebook / facebook/hhvm

PDO Persistent Connection does not do a rollback on exit if active transaction exists

Open
#7,699 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
18.7k
Forks
3.1k
Avg merge
1h 47m
Merged PRs (30d)
2

Description

You may need to run this file up thread count times before it re-selects one of the used connections from the persistent pool.

This wont be reproducible via CLI either as the database will probably auto-rollback after the connection exists. Also If you don't use persistent connections in the code you also will not see this behavior.

### HHVM Version
3.15

### Standalone code, or other way to reproduce the problem
```
true
]);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try {
$conn->beginTransaction();
$stmt = $conn->prepare("update testtable set test = 1");
$stmt->execute();
// simulate a fatal error after executing and before committing
die;
$conn->commit();
} catch (\PDOException $e) {
print $e->getMessage() . PHP_EOL . $e->getTraceAsString();
}
```
### Expected result
Script exits normally with the below from the mysql general log using php 5.6 and php 7
```
170228 16:03:39 977 Connect root@10.1.1.30 as anonymous on test
977 Query START TRANSACTION
977 Query update testtable set test = 1
977 Query ROLLBACK

```
### Actual result
There is already an active transaction #0 pdobug/file1.php(9): PDO->beginTransaction() #1 {main}

MySQL general log does not have the ROLLBACK
```
170228 16:02:50 971 Query START TRANSACTION
971 Query update testtable set test = 1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.