-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reverb\Http\Server dispatches requests without request body (intermittently) #187
Comments
Are you sure you're running the latest version as we resolved a very similar issue a few weeks back: https://github.com/laravel/reverb/pull/87/files |
Hi Joe, I'm using v1.0.0-beta9 which includes these updates. I've sent a pull request where I believe there is an error: if ($connection->bufferLength() < $contentLength[0] ?? 0) should be if ($request->getBody()->getSize() < $contentLength[0] ?? 0) Content-Length should be compared to the length of the body only since the length of the buffer also includes the headers. After this, the incomplete requests are rejected as
|
@stephenfrank Your assumption is correct about how the buffer will continue to be filled until the end of body symbol is received. Your logic makes sense to me, but I'm not sure how this is the first time it has been raised. Assuming the values in your last messages are from log statements, could you also include the value of |
I agree, seems like something that would have come up. Here is the same logging with the buffers length:
Running in Request.php public static function from(string $message, Connection $connection, int $maxRequestSize): ?RequestInterface
{
$connection->appendToBuffer($message);
if ($connection->bufferLength() > $maxRequestSize) {
throw new OverflowException('Maximum HTTP buffer size of '.$maxRequestSize.'exceeded.');
}
if (static::isEndOfMessage($buffer = $connection->buffer())) {
$request = Message::parseRequest($buffer);
$t = microtime(true);
echo "$t | ->\n";
echo "$t | Connection Buffer> {$connection->bufferLength()}\n";
echo "$t | Request Content-Length> {$request->getHeader('Content-Length')[0]}\n";
echo "$t | Request Body> {$request->getBody()->getSize()}\n";
if (! $contentLength = $request->getHeader('Content-Length')) {
return $request;
}
if ($request->getBody()->getSize() < $contentLength[0] ?? 0) {
return null;
}
$connection->clearBuffer();
return $request;
}
return null;
} Running on Docker / Macbook / ARM64:
|
Do the second and third logs comprise a single request? |
Yes, sorry maybe I could explain better... Request 1)
Request 2)
|
I'm still intrigued to know why your requests are getting split up like that, but I've tested your PR and all looks good so going to recommend this gets merged. Thanks for digging into this one 👍 |
Reverb Version
1.0.0-beta9
Laravel Version
11.6.0
PHP Version
8.2.9
Description
I have an issue where requests are intermittently dispatched without the request body.
I've tracked it down to the React PHP connection
$connection->on('data'
receiving the data in two chunks. eg. the headers in the first chunk and the body in the second chunk.Gives this output (edited for brevity)
I've hacked together a solution that solves this issue for me... essentially parsing the Content-Length header and waiting for the complete body before proceeding (it's just a proof of concept)
The ReactPHP HTTP server implementation has similar buffering to handle the full request body:
https://github.com/reactphp/http/blob/1.x/src/Middleware/RequestBodyBufferMiddleware.php
Steps To Reproduce
I'm only running this on my local development environment so can't say for sure how to reproduce.
The text was updated successfully, but these errors were encountered: