Skip to content

Commit

Permalink
Fix issue #371
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 10, 2024
1 parent 955b246 commit e1c3e1e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/Driver/Http1Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ public function handleClient(
continue;
}

$this->suspendTimeout();

$this->currentBuffer = $buffer;
$this->handleRequest($request);
$this->pendingResponseCount--;
Expand Down Expand Up @@ -740,7 +742,7 @@ static function (int $bodySize) use (&$bodySizeLimit): void {
$this->bodyQueue = null;
$queue->complete();

$this->updateTimeout();
$this->suspendTimeout();

if ($this->http2driver) {
continue;
Expand Down Expand Up @@ -802,6 +804,11 @@ private function updateTimeout(): void
self::getTimeoutQueue()->update($this->client, 0, $this->connectionTimeout);
}

private function suspendTimeout(): void
{
self::getTimeoutQueue()->suspend($this->client, 0);
}

private function removeTimeout(): void
{
self::getTimeoutQueue()->remove($this->client, 0);
Expand Down
13 changes: 11 additions & 2 deletions src/Driver/Http2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,13 @@ private function updateTimeout(int $id): void
}
}

private function suspendTimeout(int $id): void
{
if ($id & 1) {
self::getTimeoutQueue()->suspend($this->client, $id);
}
}

private function readPreface(): string
{
$buffer = $this->readableStream->read();
Expand Down Expand Up @@ -899,8 +906,6 @@ public function handleHeaders(int $streamId, array $pseudo, array $headers, bool
// Header frames can be received on previously opened streams (trailer headers).
$this->remoteStreamId = \max($streamId, $this->remoteStreamId);

$this->updateTimeout($streamId);

if (isset($this->trailerDeferreds[$streamId]) && $stream->state & Http2Stream::RESERVED) {
if (!$streamEnded) {
throw new Http2ConnectionException(
Expand Down Expand Up @@ -932,12 +937,16 @@ public function handleHeaders(int $streamId, array $pseudo, array $headers, bool

unset($this->bodyQueues[$streamId], $this->trailerDeferreds[$streamId]);

$this->suspendTimeout($streamId);

$queue->complete();
$deferred->complete($headers);

return;
}

$this->updateTimeout($streamId);

if ($stream->state & Http2Stream::RESERVED) {
throw new Http2StreamException(
"Stream already reserved",
Expand Down
10 changes: 9 additions & 1 deletion src/Driver/Internal/TimeoutQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ private function makeId(Client $client, int $streamId): string
public function update(Client $client, int $streamId, int $timeout): void
{
$cacheId = $this->makeId($client, $streamId);
\assert(isset($this->callbacks[$cacheId]));
\assert(isset($this->callbacks[$cacheId], $this->streamNames[$client][$streamId]));

$this->timeoutCache->update($cacheId, $this->now + $timeout);
}

public function suspend(Client $client, int $streamId): void
{
$cacheId = $this->makeId($client, $streamId);
\assert(isset($this->callbacks[$cacheId], $this->streamNames[$client][$streamId]));

$this->timeoutCache->clear($cacheId);
}

/**
* Remove the given stream ID.
*/
Expand Down

0 comments on commit e1c3e1e

Please sign in to comment.