Skip to content

Commit 3804e3b

Browse files
committed
Only ignore exception if client closed
1 parent 6219ec4 commit 3804e3b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Websocket.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private function reapClient(
121121
private function handleClient(WebsocketClient $client, Request $request, Response $response): void
122122
{
123123
$client->onClose(function (int $clientId, WebsocketCloseInfo $closeInfo): void {
124-
/** @psalm-suppress RedundantCondition */
124+
/** @psalm-suppress RedundantCondition */
125125
\assert($this->logger->debug(\sprintf(
126126
'Closed websocket connection #%d (code: %d) %s',
127127
$clientId,
@@ -151,9 +151,12 @@ private function handleClient(WebsocketClient $client, Request $request, Respons
151151

152152
try {
153153
$this->clientHandler->handleClient($client, $request, $response);
154-
} catch (WebsocketClosedException) {
155-
// Ignore WebsocketClosedException thrown from closing the client while streaming a message.
156154
} catch (\Throwable $exception) {
155+
if ($exception instanceof WebsocketClosedException && $client->isClosed()) {
156+
// Ignore WebsocketClosedException thrown from closing the client while streaming a message.
157+
return;
158+
}
159+
157160
$this->logger->error(
158161
\sprintf(
159162
"Unexpected %s thrown from %s::handleClient(), closing websocket connection from %s.",

0 commit comments

Comments
 (0)