Skip to content

Commit

Permalink
[HttpFoundation] Break infinite loop in PdoSessionHandler when MySQL …
Browse files Browse the repository at this point in the history
…is in loose mode
  • Loading branch information
nicolas-grekas authored and fabpot committed May 23, 2018
1 parent eff0bf4 commit 59d936e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Session/Storage/Handler/PdoSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ private function doRead($sessionId)
$selectSql = $this->getSelectSql();
$selectStmt = $this->pdo->prepare($selectSql);
$selectStmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);
$insertStmt = null;

do {
$selectStmt->execute();
Expand All @@ -509,6 +510,11 @@ private function doRead($sessionId)
return is_resource($sessionRows[0][0]) ? stream_get_contents($sessionRows[0][0]) : $sessionRows[0][0];
}

if (null !== $insertStmt) {
$this->rollback();
throw new \RuntimeException('Failed to read session: INSERT reported a duplicate id but next SELECT did not return any data.');
}

if (self::LOCK_TRANSACTIONAL === $this->lockMode && 'sqlite' !== $this->driver) {
// Exclusive-reading of non-existent rows does not block, so we need to do an insert to block
// until other connections to the session are committed.
Expand Down

0 comments on commit 59d936e

Please sign in to comment.