Skip to content

Commit f558e40

Browse files
abnegateclaude
andcommitted
fix: Pool setTimeout state tracking and MySQL timeout dirty flag
- Pool::setTimeout() now stores timeout locally so delegate() correctly propagates it to child adapters on subsequent calls - MySQL timeout uses dirty flag to only issue SET SESSION MAX_EXECUTION_TIME when timeout state actually changes, avoiding overhead on every query - MySQL::clearTimeout() marks dirty flag so the next execute() clears the session variable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79eaeb4 commit f558e40

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/Database/Adapter/MySQL.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function capabilities(): array
5454
*
5555
* @throws DatabaseException
5656
*/
57+
private bool $timeoutDirty = false;
58+
5759
public function setTimeout(int $milliseconds, Event $event = Event::All): void
5860
{
5961
if (! $this->supports(Capability::Timeouts)) {
@@ -64,11 +66,23 @@ public function setTimeout(int $milliseconds, Event $event = Event::All): void
6466
}
6567

6668
$this->timeout = $milliseconds;
69+
$this->timeoutDirty = true;
70+
}
71+
72+
public function clearTimeout(Event $event = Event::All): void
73+
{
74+
if ($this->timeout > 0) {
75+
$this->timeoutDirty = true;
76+
}
77+
$this->timeout = 0;
6778
}
6879

6980
protected function execute(mixed $stmt): bool
7081
{
71-
$this->getPDO()->exec("SET SESSION MAX_EXECUTION_TIME = {$this->timeout}");
82+
if ($this->timeoutDirty) {
83+
$this->getPDO()->exec("SET SESSION MAX_EXECUTION_TIME = {$this->timeout}");
84+
$this->timeoutDirty = false;
85+
}
7286
/** @var PDOStatement|\Swoole\Database\PDOStatementProxy $stmt */
7387
return $stmt->execute();
7488
}

src/Database/Adapter/Pool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public function removeQueryTransform(string $name): static
151151
*/
152152
public function setTimeout(int $milliseconds, Event $event = Event::All): void
153153
{
154+
$this->timeout = $milliseconds;
154155
$this->delegate(__FUNCTION__, \func_get_args());
155156
}
156157

0 commit comments

Comments
 (0)