Skip to content

Commit 56ca509

Browse files
authored
Added SafeCaller to avoid server shutdown which caused by exceptions. (#4688)
1 parent 7fe6856 commit 56ca509

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Server.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Hyperf\Server\Event;
3737
use Hyperf\Server\Server as AsyncStyleServer;
3838
use Hyperf\Server\ServerManager;
39+
use Hyperf\Utils\SafeCaller;
3940
use Hyperf\WebSocketServer\Collector\FdCollector;
4041
use Hyperf\WebSocketServer\Context as WsContext;
4142
use Hyperf\WebSocketServer\Exception\Handler\WebSocketExceptionHandler;
@@ -160,7 +161,12 @@ public function onHandShake($request, $response): void
160161
}
161162
} catch (Throwable $throwable) {
162163
// Delegate the exception to exception handler.
163-
$psr7Response = $this->exceptionHandlerDispatcher->dispatch($throwable, $this->exceptionHandlers);
164+
$psr7Response = $this->container->get(SafeCaller::class)->call(function () use ($throwable) {
165+
return $this->exceptionHandlerDispatcher->dispatch($throwable, $this->exceptionHandlers);
166+
}, static function () {
167+
return (new Psr7Response())->withStatus(400);
168+
});
169+
164170
isset($fd) && FdCollector::del($fd);
165171
isset($fd) && WsContext::release($fd);
166172
} finally {

0 commit comments

Comments
 (0)