Skip to content

Commit e9adfb7

Browse files
authored
Fixed bug that worker will be stoped when onMessage or onClose failed in websocket server. (#2915)
* Fixed bug that worker will be stoped when `onMessage` or `onClose` failed in websocket server. * Update CHANGELOG-2.0.md
1 parent 8d9fd71 commit e9adfb7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Server.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ public function onMessage($server, Frame $frame): void
231231
return;
232232
}
233233

234-
$instance->onMessage($server, $frame);
234+
try {
235+
$instance->onMessage($server, $frame);
236+
} catch (\Throwable $exception) {
237+
$this->logger->error((string) $exception);
238+
}
235239
}
236240

237241
public function onClose($server, int $fd, int $reactorId): void
@@ -252,7 +256,11 @@ public function onClose($server, int $fd, int $reactorId): void
252256

253257
$instance = $this->container->get($fdObj->class);
254258
if ($instance instanceof OnCloseInterface) {
255-
$instance->onClose($server, $fd, $reactorId);
259+
try {
260+
$instance->onClose($server, $fd, $reactorId);
261+
} catch (\Throwable $exception) {
262+
$this->logger->error((string) $exception);
263+
}
256264
}
257265
}
258266

0 commit comments

Comments
 (0)