Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,11 @@ private function shutdown(?HttpException $reason = null, ?int $lastId = null): v
default => null,
};

$this->writeFrame(Http2Parser::GOAWAY, data: \pack('NN', 0, $code) . $message)->ignore();
// Without active streams nothing else closes the socket, see releaseStream(). Closing it right away
// would discard the GOAWAY frame still waiting in the write queue.
$this->writeFrame(Http2Parser::GOAWAY, data: \pack('NN', 0, $code) . $message)
->finally($this->socket->close(...))
->ignore();

foreach ($this->streams as $id => $_stream) {
$reason ??= $this->makeDefaultShutdownReason();
Expand Down
16 changes: 16 additions & 0 deletions test/Connection/Http2ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ public function testServerGoAwayFrame(): void
}
}

public function testCloseWithoutStreamsClosesSocket(): void
{
$this->connection->close();

$received = '';
while (null !== $chunk = $this->server->read(new TimeoutCancellation(1))) {
$received .= $chunk;
}

self::assertTrue($this->client->isClosed());
self::assertStringEndsWith(
self::packFrame(\pack('NN', 0, Http2Parser::GRACEFUL_SHUTDOWN), Http2Parser::GOAWAY),
$received,
);
}

public function testServerEarlyResponse(): void
{
$request = new Request('http://localhost/', 'POST', BufferedContent::fromString(\str_repeat('a', 2 ** 10)));
Expand Down
Loading