diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md index 1e7b6ecd5b..229d1f2474 100644 --- a/CHANGELOG-3.1.md +++ b/CHANGELOG-3.1.md @@ -1,5 +1,9 @@ # v3.1.10 - TBD +## Fixed + +- [#6525](https://github.com/hyperf/hyperf/pull/6525) Fixed the bug that `CoroutineServer` process exit when input variables exceeded. + # v3.1.9 - 2024-02-18 ## Fixed diff --git a/src/exception-handler/src/Listener/ErrorExceptionHandler.php b/src/exception-handler/src/Listener/ErrorExceptionHandler.php index f28e361474..1b007e4898 100644 --- a/src/exception-handler/src/Listener/ErrorExceptionHandler.php +++ b/src/exception-handler/src/Listener/ErrorExceptionHandler.php @@ -12,11 +12,22 @@ namespace Hyperf\ExceptionHandler\Listener; use ErrorException; +use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Framework\Event\BootApplication; +use Psr\Container\ContainerInterface; class ErrorExceptionHandler implements ListenerInterface { + protected ?StdoutLoggerInterface $logger = null; + + public function __construct(ContainerInterface $container) + { + if ($container->has(StdoutLoggerInterface::class)) { + $this->logger = $container->get(StdoutLoggerInterface::class); + } + } + public function listen(): array { return [ @@ -26,8 +37,18 @@ public function listen(): array public function process(object $event): void { - set_error_handler(static function ($level, $message, $file = '', $line = 0): bool { + $logger = $this->logger; + set_error_handler(static function ($level, $message, $file = '', $line = 0) use ($logger): bool { if (error_reporting() & $level) { + if ($line === 0) { + if ($logger) { + $logger->error($message); + } else { + echo $message . PHP_EOL; + } + return true; + } + throw new ErrorException($message, 0, $level, $file, $line); } diff --git a/src/exception-handler/tests/ErrorExceptionHandlerTest.php b/src/exception-handler/tests/ErrorExceptionHandlerTest.php index d3a3f177f2..cdd1e22a36 100644 --- a/src/exception-handler/tests/ErrorExceptionHandlerTest.php +++ b/src/exception-handler/tests/ErrorExceptionHandlerTest.php @@ -13,6 +13,7 @@ use ErrorException; use Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler; +use Mockery; use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\Attributes\WithoutErrorHandler; use PHPUnit\Framework\TestCase; @@ -24,10 +25,17 @@ #[CoversNothing] class ErrorExceptionHandlerTest extends TestCase { + protected function tearDown(): void + { + Mockery::close(); + } + #[WithoutErrorHandler] public function testHandleError() { - $listener = new ErrorExceptionHandler(); + $container = Mockery::mock(\Psr\Container\ContainerInterface::class); + $container->shouldReceive('has')->with(\Hyperf\Contract\StdoutLoggerInterface::class)->andReturn(false); + $listener = new ErrorExceptionHandler($container); $listener->process((object) []); $this->expectException(ErrorException::class);