From 44efff94edea665046a2a269e9e7794995bd2a0b Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Tue, 24 Dec 2024 12:26:20 +0100 Subject: [PATCH] refactor: always clean up sockets --- .../Components/Interactive/TaskComponent.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Tempest/Console/src/Components/Interactive/TaskComponent.php b/src/Tempest/Console/src/Components/Interactive/TaskComponent.php index 3b931c0cb..6fc327a94 100644 --- a/src/Tempest/Console/src/Components/Interactive/TaskComponent.php +++ b/src/Tempest/Console/src/Components/Interactive/TaskComponent.php @@ -104,8 +104,10 @@ public function render(Terminal $terminal): Generator } } finally { if ($this->state->isFinished() && $this->processId) { - $this->kill(); + posix_kill($this->processId, SIGTERM); } + + $this->cleanupSockets(); } } @@ -124,14 +126,15 @@ private function renderTask(Terminal $terminal, ?string $line = null): string ); } - private function kill(): void + private function cleanupSockets(): void { - try { - posix_kill($this->processId, SIGTERM); - @fclose($this->sockets[0]); - @fclose($this->sockets[1]); - } catch (Throwable) { + foreach ($this->sockets as $socket) { + if (is_resource($socket)) { + @fclose($socket); + } } + + $this->sockets = []; } private function executeHandler(): void