diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index 392e81a83..5343f7243 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -9,6 +9,7 @@ - [#2210](https://github.com/hyperf/hyperf/pull/2210) Fixed bug that open event won't be executed after handshake right now. - [#2214](https://github.com/hyperf/hyperf/pull/2214) Fixed bug that close event won't be executed when close the connection by websocket server. - [#2218](https://github.com/hyperf/hyperf/pull/2218) Fixed bug that sender does not works for coroutine server. +- [#2227](https://github.com/hyperf/hyperf/pull/2227) Fixed context won't be destroyed when accept keepalive connection for co server. ## Optimized diff --git a/src/server/src/CoroutineServer.php b/src/server/src/CoroutineServer.php index 3cfa498fb..904c0d4c0 100644 --- a/src/server/src/CoroutineServer.php +++ b/src/server/src/CoroutineServer.php @@ -145,7 +145,11 @@ class CoroutineServer implements ServerInterface $handler->initCoreMiddleware($name); } if ($this->server instanceof \Swoole\Coroutine\Http\Server) { - $this->server->handle('/', [$handler, $method]); + $this->server->handle('/', static function ($request, $response) use ($handler, $method) { + Coroutine::create(static function () use ($request, $response, $handler, $method) { + $handler->{$method}($request, $response); + }); + }); } } return;