mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 13:18:22 +08:00
Fixed the dead cycle caused by socket closed.
This commit is contained in:
parent
639f2b7a9a
commit
37cacf16a8
@ -18,6 +18,7 @@ use Hyperf\ExceptionHandler\Formatter\FormatterInterface;
|
||||
use Hyperf\Process\Event\AfterProcessHandle;
|
||||
use Hyperf\Process\Event\BeforeProcessHandle;
|
||||
use Hyperf\Process\Event\PipeMessage;
|
||||
use Hyperf\Process\Exception\SocketClosedException;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Swoole\Coroutine\Channel;
|
||||
@ -137,6 +138,9 @@ abstract class AbstractProcess implements ProcessInterface
|
||||
/** @var \Swoole\Coroutine\Socket $sock */
|
||||
$sock = $this->process->exportSocket();
|
||||
$recv = $sock->recv($this->recvLength, $this->recvTimeout);
|
||||
if ($recv === '') {
|
||||
throw new SocketClosedException('Socket is closed.');
|
||||
}
|
||||
if ($this->event && $recv !== false && $data = unserialize($recv)) {
|
||||
$this->event->dispatch(new PipeMessage($data));
|
||||
}
|
||||
@ -146,6 +150,10 @@ abstract class AbstractProcess implements ProcessInterface
|
||||
$formatter = $this->container->get(FormatterInterface::class);
|
||||
$logger->error($formatter->format($exception));
|
||||
}
|
||||
|
||||
if ($exception instanceof SocketClosedException) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
$quit->close();
|
||||
|
19
src/process/src/Exception/SocketClosedException.php
Normal file
19
src/process/src/Exception/SocketClosedException.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://doc.hyperf.io
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace Hyperf\Process\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class SocketClosedException extends RuntimeException
|
||||
{
|
||||
}
|
Loading…
Reference in New Issue
Block a user