mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-04 20:58:13 +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));
|
$this->logger->debug(sprintf('WebSocket: fd[%d] closed.', $fd));
|
||||||
|
|
||||||
Context::set(WsContext::FD, $fd);
|
|
||||||
$fdObj = FdCollector::get($fd);
|
$fdObj = FdCollector::get($fd);
|
||||||
if (! $fdObj) {
|
if (! $fdObj) {
|
||||||
return;
|
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);
|
$instance = $this->container->get($fdObj->class);
|
||||||
if ($instance instanceof OnCloseInterface) {
|
if ($instance instanceof OnCloseInterface) {
|
||||||
$instance->onClose($server, $fd, $reactorId);
|
$instance->onClose($server, $fd, $reactorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
FdCollector::del($fd);
|
|
||||||
WsContext::release($fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user