forked from leftypol/leftypol
anti-bot.php: retry transaction upon deadlock
This commit is contained in:
parent
21155cbb06
commit
b03130fcb4
1 changed files with 38 additions and 31 deletions
|
@ -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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue