diff --git a/README.md b/README.md index 02202594..9d1f133e 100644 --- a/README.md +++ b/README.md @@ -2683,7 +2683,8 @@ access its underlying response object. #### InactiveConnectionTimeoutMiddleware The `React\Http\Middleware\InactiveConnectionTimeoutMiddleware` is purely a configuration middleware to configure the -`HttpServer` to close any inactive connections between requests to close the connection and not leave them needlessly open. +`HttpServer` to close any inactive connections between requests to close the connection and not leave them needlessly +open. The default is `60` seconds of inactivity and should only be changed if you know what you are doing. The following example configures the `HttpServer` to close any inactive connections after one and a half second: @@ -2695,6 +2696,8 @@ $http = new React\Http\HttpServer( ``` > Internally, this class is used as a "value object" to override the default timeout of one minute. As such it doesn't have any behavior internally, that is all in the internal "StreamingServer". + This timeout is only in effect if we expect data from the client, not when we are writing data to + the client. #### StreamingRequestMiddleware diff --git a/src/Io/StreamingServer.php b/src/Io/StreamingServer.php index 4e1907e8..fcf1fa19 100644 --- a/src/Io/StreamingServer.php +++ b/src/Io/StreamingServer.php @@ -418,7 +418,11 @@ public function parseRequest(ConnectionInterface $connection) }; $connection->once('close', $closeTimerCanceler); $connection->once('data', $dataTimerCanceler); - $removeTimerHandler = function () use ($parser, $connection, $closeTimerCanceler, $dataTimerCanceler, &$removeTimerHandler) { + $removeTimerHandler = function ($_, $conn) use ($parser, $connection, $closeTimerCanceler, $dataTimerCanceler, &$removeTimerHandler) { + if (\spl_object_hash($conn) !== \spl_object_hash($connection)) { + return; + } + $connection->removeListener('close', $closeTimerCanceler); $connection->removeListener('data', $dataTimerCanceler); $parser->removeListener('headers', $removeTimerHandler);