Skip to content

Commit 1844947

Browse files
committed
Close inactive connections and requests
This new middleware introduces a timeout of closing inactive connections between requests after a configured amount of seconds. This builds on top of #405 and partially on #422
1 parent cca3125 commit 1844947

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,8 @@ access its underlying response object.
26832683
#### InactiveConnectionTimeoutMiddleware
26842684

26852685
The `React\Http\Middleware\InactiveConnectionTimeoutMiddleware` is purely a configuration middleware to configure the
2686-
`HttpServer` to close any inactive connections between requests to close the connection and not leave them needlessly open.
2686+
`HttpServer` to close any inactive connections between requests to close the connection and not leave them needlessly
2687+
open. The default is `60` seconds of inactivity and should only be changed if you know what you are doing.
26872688

26882689
The following example configures the `HttpServer` to close any inactive connections after one and a half second:
26892690

src/Io/StreamingServer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ public function parseRequest(ConnectionInterface $connection)
418418
};
419419
$connection->once('close', $closeTimerCanceler);
420420
$connection->once('data', $dataTimerCanceler);
421-
$removeTimerHandler = function () use ($parser, $connection, $closeTimerCanceler, $dataTimerCanceler, &$removeTimerHandler) {
421+
$removeTimerHandler = function ($_, $conn) use ($parser, $connection, $closeTimerCanceler, $dataTimerCanceler, &$removeTimerHandler) {
422+
if (\spl_object_hash($conn) !== \spl_object_hash($connection)) {
423+
return;
424+
}
425+
422426
$connection->removeListener('close', $closeTimerCanceler);
423427
$connection->removeListener('data', $dataTimerCanceler);
424428
$parser->removeListener('headers', $removeTimerHandler);

0 commit comments

Comments
 (0)