Skip to content

Commit

Permalink
Restore needed async call
Browse files Browse the repository at this point in the history
Read the spec wrong, CONTINATION frame ordering limitation is connection-wide, not stream specific.

This was incorrect before, as the last write needed to use async() too.
  • Loading branch information
trowski committed Oct 25, 2020
1 parent 9686919 commit eaddd0a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Connection/Internal/Http2ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,13 +1020,15 @@ public function request(Request $request, CancellationToken $cancellationToken,
$firstChunk = \array_shift($split);
$lastChunk = \array_pop($split);

$this->writeFrame(Http2Parser::HEADERS, Http2Parser::NO_FLAG, $streamId, $firstChunk);
// Use async for each write to ensure no other frames are written to the connection.
async(fn() => $this->writeFrame(Http2Parser::HEADERS, Http2Parser::NO_FLAG, $streamId, $firstChunk));

foreach ($split as $headerChunk) {
$this->writeFrame(Http2Parser::CONTINUATION, Http2Parser::NO_FLAG, $streamId, $headerChunk);
async(fn() => $this->writeFrame(Http2Parser::CONTINUATION, Http2Parser::NO_FLAG, $streamId, $headerChunk));
}

$this->writeFrame(Http2Parser::CONTINUATION, $flag, $streamId, $lastChunk);
// Use async for last write to keep ordering, but await completion of write.
await(async(fn() => $this->writeFrame(Http2Parser::CONTINUATION, $flag, $streamId, $lastChunk)));
} else {
$this->writeFrame(Http2Parser::HEADERS, $flag, $streamId, $headers);
}
Expand Down Expand Up @@ -1134,9 +1136,9 @@ private function run(): void
$parser = (new Http2Parser($this))->parse();

while (null !== $chunk = $this->socket->read()) {
$return = $parser->send($chunk);
$yielded = $parser->send($chunk);

\assert($return === null);
\assert($yielded === null);
}

$this->shutdown();
Expand Down

0 comments on commit eaddd0a

Please sign in to comment.