Skip to content

Commit

Permalink
Compete frame queue when shutting down
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Nov 18, 2022
1 parent 410c704 commit c57531f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ private function writeFrame(
int $stream = 0,
string $data = ''
): Future {
if ($this->frameQueue->isComplete() || $this->frameQueue->isDisposed()) {
if ($this->shutdown !== null) {
return Future::complete();
}

Expand Down Expand Up @@ -1414,24 +1414,20 @@ private function shutdown(?HttpException $reason = null, ?int $lastId = null): v
Http2Parser::INTERNAL_ERROR,
);

$this->shutdown = (int) $reason->getCode();

if ($this->settings !== null) {
$message = "Connection closed before HTTP/2 settings could be received";
$this->settings->error(new UnprocessedRequestException(new SocketException($message, 0, $reason)));
$this->settings = null;
}

if ($this->streams) {
foreach ($this->streams as $id => $stream) {
if ($lastId !== null && $id > $lastId) {
$reason = $reason instanceof UnprocessedRequestException
? $reason
: new UnprocessedRequestException($reason);
}

$this->releaseStream($id, $reason);
foreach ($this->streams as $id => $stream) {
if ($lastId !== null && $id > $lastId) {
$reason = $reason instanceof UnprocessedRequestException
? $reason
: new UnprocessedRequestException($reason);
}

$this->releaseStream($id, $reason);
}

$this->cancelPongWatcher(false);
Expand All @@ -1446,6 +1442,9 @@ private function shutdown(?HttpException $reason = null, ?int $lastId = null): v
}
}

$this->shutdown = (int) $reason->getCode();
$this->frameQueue->complete();

\assert(empty($this->streams), 'Streams array not empty after shutdown');
}

Expand Down

0 comments on commit c57531f

Please sign in to comment.