mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 04:37:46 +08:00
use defer to reclaim resources
Signed-off-by: reasno <guxi99@gmail.com>
This commit is contained in:
parent
e5a94460b9
commit
c97899db7f
@ -189,18 +189,20 @@ class Server implements MiddlewareInitializerInterface, OnHandShakeInterface, On
|
||||
{
|
||||
$this->logger->debug(sprintf('WebSocket: fd[%d] closed.', $fd));
|
||||
|
||||
Context::set(WsContext::FD, $fd);
|
||||
$fdObj = FdCollector::get($fd);
|
||||
if (! $fdObj) {
|
||||
return;
|
||||
}
|
||||
Context::set(WsContext::FD, $fd);
|
||||
defer(function () use ($fd) {
|
||||
// Move those functions to defer, because onClose may throw exceptions
|
||||
FdCollector::del($fd);
|
||||
WsContext::release($fd);
|
||||
});
|
||||
$instance = $this->container->get($fdObj->class);
|
||||
if ($instance instanceof OnCloseInterface) {
|
||||
$instance->onClose($server, $fd, $reactorId);
|
||||
}
|
||||
|
||||
FdCollector::del($fd);
|
||||
WsContext::release($fd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user