Skip to content
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

[2.x] Prevents FPM from crashing when body is sent with a GET request #155

Merged
merged 10 commits into from
Sep 6, 2023
Merged
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
1 change: 0 additions & 1 deletion src/Runtime/Handlers/FpmHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FpmHandler implements LambdaEventHandler
/**
* Handle an incoming Lambda event.
*
* @param array $event
* @return \Laravel\Vapor\Contracts\LambdaResponse
*/
public function handle(array $event)
Expand Down
20 changes: 17 additions & 3 deletions stubs/fpmRuntime.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

use hollodotme\FastCGI\Exceptions\WriteFailedException;
use Illuminate\Contracts\Console\Kernel as ConsoleKernelContract;
use Illuminate\Support\Str;
use Laravel\Vapor\Runtime\Environment;
use Laravel\Vapor\Runtime\Fpm\Fpm;
use Laravel\Vapor\Runtime\Fpm\FpmHttpHandlerFactory;
use Laravel\Vapor\Runtime\LambdaContainer;
use Laravel\Vapor\Runtime\LambdaResponse;
use Laravel\Vapor\Runtime\LambdaRuntime;
use Laravel\Vapor\Runtime\Secrets;
use Laravel\Vapor\Runtime\StorageDirectories;
Expand Down Expand Up @@ -96,9 +99,20 @@ function_exists('__vapor_debug') && __vapor_debug('Preparing to boot FPM');

while (true) {
$lambdaRuntime->nextInvocation(function ($invocationId, $event) {
return FpmHttpHandlerFactory::make($event)
->handle($event)
->toApiGatewayFormat();
try {
return FpmHttpHandlerFactory::make($event)
->handle($event)
->toApiGatewayFormat();
} catch (WriteFailedException $e) {
if (Str::contains($e->getMessage(), 'Failed to write request to socket [broken pipe]')) {
function_exists('__vapor_debug') && __vapor_debug($e->getMessage());

return (new LambdaResponse(403, [], ''))
->toApiGatewayFormat();
}

throw $e;
}
});

$fpm->ensureRunning();
Expand Down
Loading