anti-bot.php: retry transaction upon deadlock

This commit is contained in:
Zankaria 2024-12-17 17:13:10 +01:00
parent 21155cbb06
commit b03130fcb4

View file

@ -195,6 +195,8 @@ function _create_antibot($pdo, $board, $thread) {
$antibot = new AntiBot(array($board, $thread)); $antibot = new AntiBot(array($board, $thread));
try {
retry_on_deadlock(3, function() use ($config, $pdo, $thread, $board, $antibot) {
try { try {
$pdo->beginTransaction(); $pdo->beginTransaction();
@ -233,12 +235,17 @@ function _create_antibot($pdo, $board, $thread) {
$query->execute(); $query->execute();
$pdo->commit(); $pdo->commit();
} catch (\Exception $e) {
$pdo->rollBack();
throw $e;
}
});
} catch (\PDOException $e) { } catch (\PDOException $e) {
$pdo->rollBack(); $pdo->rollBack();
if ($e->errorInfo === null || $e->errorInfo[1] != MYSQL_ER_LOCK_DEADLOCK) { if ($e->errorInfo === null || $e->errorInfo[1] != MYSQL_ER_LOCK_DEADLOCK) {
throw $e; throw $e;
} else { } else {
error_log('Deadlock on _create_antibot while inserting, skipping'); \error_log('5 or more deadlocks on _create_antibot while inserting, skipping');
} }
} }