Skip to content

Commit

Permalink
refactor: always clean up sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Dec 24, 2024
1 parent d08549f commit 44efff9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Tempest/Console/src/Components/Interactive/TaskComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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
Expand Down

0 comments on commit 44efff9

Please sign in to comment.