Closed kwn closed 5 years ago
Thank you for the details and the repository. This is indeed weird and definitely something we want to fix.
I tried reproducing the error but it is all working fine (at least locally) for me with your test repository.
We are discussing that in Slack (https://bref.sh/docs/community.html), feel free to post here or join in the chat.
A quick note: could it be a matter of response size? I see in your test repository that you return a pretty large JSON response.
Thank you for the answer.
Could you try to reproduce the issue locally by calling the endpoint multiple times? I observed it's failing randomly (roughly 1 per 4 requests). Also I noticed it's failing more often under heavier load (processing e.g. 2 or 3 requests in the same time. The behaviour is exactly the same in real AWS environment.
Response size - possibly. Just tried to reduce the size of a response to ~100kB. I'm still able to reproduce an issue but now it's crashing once every ~50 requests.
We spent some time trying to understand why does that happen. Looking into e.g. UTF/weird characters in the response, missing headers etc, but we still have no clue why is it failing. The non-deterministic nature of the issue suggests that we should look into some timeout related problems - but definitely hard to say what's going on.
The execution time itself and the init duration I think is not an issue. Some examples:
failed - Init Duration: 220.98 ms Duration: 67.66 ms
passed - Init Duration: 132.76 ms Duration: 27.27 ms
passed - Init Duration: 322.23 ms Duration: 60.90 ms
passed - Init Duration: 465.60 ms Duration: 144.71 ms
@kwn I have opened #318 (to reproduce) and #319 (to fix).
If you have a chance to try #319 and confirm if it solves the issues for you that would be awesome.
Sure, thank you. I'm going to take a look at it tomorrow.
@mnapoli I just tested with https://github.com/mnapoli/bref/pull/319 and it works like a charm đź‘Ť
Just tested locally in my machine and also works for me (didn't try in real AWS though).
Thank you!!!!!!! @mnapoli
Hi @mnapoli, We are getting the same error what you have mentioned in this issue. We are using serverless template to deploy Lambda function in aws. we followed this tutorial to deploy laravel code to lambda: https://www.youtube.com/watch?v=rWExnXzUBqc
we got this error from cloud watch:
"errorType": "Bref\\Event\\Http\\FastCgi\\FastCgiCommunicationFailed",
"errorMessage": "Error communicating with PHP-FPM to read the HTTP response. A root cause of this can be that the Lambda (or PHP) timed out, for example when trying to connect to a remote API or database, if this happens continuously check for those! Original exception message: hollodotme\\FastCGI\\Exceptions\\TimedoutException Read timed out",
"stack": [
"#0 /var/task/vendor/bref/bref/src/Event/Http/HttpHandler.php(22): Bref\\Event\\Http\\FpmHandler->handleRequest(Object(Bref\\Event\\Http\\HttpRequestEvent), Object(Bref\\Context\\Context))",
"#1 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(104): Bref\\Event\\Http\\HttpHandler->handle(Array, Object(Bref\\Context\\Context))",
"#2 /opt/bootstrap(35): Bref\\Runtime\\LambdaRuntime->processNextEvent(Object(Bref\\Event\\Http\\FpmHandler))",
"#3 {main}"
]
We don't know how to Migrate from hoa/fastcgi to hollodotme/fast-cgi-client we did not find any packages like fastcgi or any other packages related to what you have mentioned in the command section.
service: wtm-authentication-prod
provider:
name: aws
stage: prod
apiGateway:
restApiId: xxxxxx
restApiRootResourceId: xxxxxxx
region: ap-south-1
runtime:
provided
# declare one of the following...
role: arn:aws:iam::xxxxx:role/LaravelAPIRole # must validly reference a role defined in your account
plugins:
- ./vendor/bref/bref
package:
exclude:
- node_modules/**
- public/storage
- resources/assets/**
- tests/**
functions:
website:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- $**{bref:layer.php-73-fpm}**
events:
- http:
path: /authservices/api/login
method: "POST"
cors: true # <-- CORS!
This issue is from 2019, please open a new one as this is very likely not related.
You don't have to install anything new. Judging by serverless.yml
I guess you are not using the latest versions of Bref, you may want to upgrade Bref first.
Hi @mnapoli !
We tried to use bref and php-fpm layer but we find it very unstable. We tried to make it working with Symfony4, ApiPlatform as well as bare minimal code that sends one header echoes a response. In any case (running locally using sam and in aws environment) we observed very strange and non deterministic behaviours. Instead of getting a real response we were getting 502 response code from Sam with a response of:
The console running lambda using Sam was printing the following output:
Another weird behaviour we observed was cutting the json response in a middle and adding
[] }
at the end of it (sill not being able to produce correct json object). An example output looked like that:These were responses that were echoed directly. We didn't use database, or anything that could potentially delay the response or cause any timeout. We were getting errored responses within <1sec.
The minimal repo that allows to reproduce an issue is available here:
https://github.com/third-bridge/bref-example
Do you have any clue why is it failing? It's almost a default configuration generated by bref. We tried with different layers (v4 and v5, php-fpm 7.2 and 7.3) still getting the same results.