Symfony doesn't give full traces of Exceptions in production - php

We recently moved our infra to K8s, and since I have issue to get Traces of my Exceptions
We're on Symfony 3.4, and my Exception traces only gaves me web/app.php, but not root cause
Error: Call to a member function send() on null
#0 web/app.php(19): null
app.php is classic Symfony file, nothing relevent inside:
$kernel = new AppKernel('prod', false);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I tried to connect my localhost to my production DB, to see if I had the same issue, but no. I have correct full trace of my Exception
If I try in production with "app_dev.php" (which I enabled only for this test), I have same issue with no trace
Do you know what could cause this issue?
A PHP configuration? I checked differences between php -i on previous infra & new one, but I don't see any relevant difference
Edit:
Monolog in config.yml:
monolog:
handlers:
main:
type: rotating_file
max_files: 10
path: '%kernel.logs_dir%/%kernel.environment%.general.log'
level: INFO
formatter: myapp.monolog.formatter.json_message
Edit 2:
We bring part of old infra alive. And here the difference :
Old infra, for Fatal Errors, we have the full trace:
On new infra, same fatal error is displayed without any more detail

The issue seems to comes from datadog agent that we added on our new infra.
Edit: Issue has been fixed in https://github.com/DataDog/dd-trace-php/releases/tag/0.79.0

Related

Library error: a socket error occurred in Symfony Messenger

In my Symfony project, there is a queue message handler, and I have an error that randomly appears during the execution:
[2022-10-12T07:31:40.060119+00:00] console.CRITICAL: Error thrown while running command "messenger:consume async --limit=10". Message: "Library error: a socket error occurred" {"exception":"[object] (Symfony\\Component\\Messenger\\Exception
TransportException(code: 0): Library error: a socket error occurred at /var/www/app/vendor/symfony/amqp-messenger/Transport/AmqpReceiver.php:62)
[previous exception] [object] (AMQPException(code: 0): Library error: a socket error occurred at /var/www/app/vendor/symfony/amqp-messenger/Transport/Connection.php:439)","command":"messenger:consume async --limit=10","message":"Library error: a socket error occurred"} []
The handler executes HTTP requests that could last some seconds and the whole process of a single message could even take more than one minute if APIs are slow. The strange thing is that the problem disappears for hours but then it randomly appears again. The more messages are sent to the queue, the easier it's to see the exception.
config\packages\messenger.yaml
framework:
messenger:
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async:
dsn: "%env(MESSENGER_TRANSPORT_DSN)%"
options:
exchange:
name: async_exchange
queues:
async: ~
heartbeat: 45
write_timeout: 90
read_timeout: 90
retry_strategy:
max_retries: 0
routing:
# Route your messages to the transports
'App\Message\MessageUpdateRequest': async
App\MessageHandler\MessageUpdateRequestHandler.php
<?php
declare(strict_types=1);
namespace App\MessageHandler;
use App\Message\MessageUpdateRequest;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
class MessageUpdateRequestHandler implements MessageHandlerInterface
{
public function __invoke(MessageUpdateRequest $message)
{
// Logic executing API requests...
return 0;
}
}
Environment
Symfony Messenger: 5.4.17
PHP: 8.1
RabbitMQ: 3.11.5
Things that I tried
upgrading Symfony Messenger to 5.4.17, using the fix available here;
adding the following options: heartbeat, write_timeout and read_timeout in the messenger.yaml file.
Related issues/links
https://github.com/php-amqp/php-amqp/issues/258
https://github.com/symfony/symfony/issues/32357
https://github.com/symfony/symfony/pull/47831
How can I fix this issue?
Regarding a socket error that occurs in Symfony Messenger, I always suggest following the step-wise approach and checking if you are missing anything. It should fix this type of error almost every time. Please follow these guidelines:
Verify that the RabbitMQ service is active and accessible.
Verify that the hostname, port, username, and password are listed in the messenger.yaml file are accurate.
In the messenger.yaml file, increase the heartbeat, write timeout, and read timeout settings.
Verify your use case to determine whether the max retries number in messenger.yaml is appropriate.
Look for any network problems that could be causing the socket error.
Make sure your PHP version is compatible with RabbitMQ and Symfony Messenger.
Verify that the server's resources (CPU, Memory, and Disk) are not used up.
Look for any relevant error messages in the PHP error log.
Determine whether there is a problem with the MessageUpdateRequestHandler class's logic.
Tip: Still stuck? Try to reproduce the error with a smaller message set and in a controlled environment to isolate the root cause that we may be missing.
Hope it helps. Happy debugging and good luck.

Runtime Exception: unable to create cache directory Google App Engine Symfony2

I am working with google's app engine Symfony HelloWorld example from https://cloud.google.com/appengine/docs/php/symfony-hello-world with source taken from Github.
I have the basic case working, but when I update the AppKernal for a production release I get a fatal error in cloudstorage. The only change is in app.php from $kernel = new AppKernel(); to $kernel = new AppKernel('prod', true);
This produces the error
Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to create the cache directory (gs://symfony-sp-bucket15//symfony/cache) ' in /base/data/home/apps/s~symfony-starter-project/15.390142223904071434/app/bootstrap.php.cache:2632
I have tried clearing the cache and memcache. I've also consulted related links such as: RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev), but these do not resolve the issue on Google's App Engine. Any suggestions would be great.
Since GCS is emulated when you are testing locally, you should check if 'symfony-sp-bucket15' actually exists in your project (Storage -> Browser in the Developers Console). You may need to create it or specify a different bucket name in your config.

Symfony 2.4 You have requested a non-existent service "payment.encryption_service"

I'm migrating a symfony project from 2.0 to 2.4 version.
I've correctly configured all the parameters and services.
But the problem occured with JMS vendor, this is the error shown:
Fatal error: Uncaught exception
'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException'
with message 'You have requested a non-existent service
"payment.encryption_service".' in
C:\wamp\www\symfony\app\bootstrap.php.cache on line 2027
This message is blocking me, do you have any issue, any idea?
I had the same problem. I don't know exactly what happened, but my problems went away after I manually cleared the cache using
rm -rf app/cache/prod/*
Considering your settings are on Windows, try manually deleting entries at app\cache\prod using Windows Explorer. I couldn't use app/console cache:clear --env=prod since the console would crash after showing that error message.
Another correct answer could be checking every service.yml in yml parser, for example http://yaml-online-parser.appspot.com
You have requested a non-existent service
could mean, that symfony can't parse correctly .yml files.
This means your the mentioned parameter is missing from your app/config/parameters.yml or other alike file that you are using to store your parameters. Set this parameter to a value and it should work.
E.G. I had the same error being "You have requested a non-existent parameter "domain".
I then added following line to the parameters.yml file:
domain: example.com
That did the trick.

Setting up php-sdk-gae with symfony2

I'm trying to run symfony2 with a hello world sample bundle inside php-sdk-gae.
I'm following the instructions provided in https://developers.google.com/appengine/docs/php/ and I can run the demo with the development controller (i.e: configuring app.yaml as following:
application: helloworld
version: 1
runtime: php
api_version: 1
handlers:
- url: /bundles
static_dir: helloWorld/web/bundles
- url: /favicon.ico
static_files: helloWorld/web/favicon.ico
upload: helloWorld/web/favicon.ico
- url: /.*
script: helloWorld/web/app_dev.php
It works fine, and I am able to get a Hello World after running the server and load /hello/World page
But when I try to run it with the production controller (app.php instead app_dev.php), I get an internal server error.
Request URL:http://mysite.local:8080/hello/World
Request Method:GET
Status Code:500 Internal Server Error
The only clue is in the console window where I launched the server, showing the lines ...
ERROR:root:php failure (255) with:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.15
Content-type: text/html
If I make some changes in app.php files, I realize that it works fine with following AppKernel loading lines:
$kernel = new AppKernel('prod', true);
$kernel = new AppKernel('dev', false);
$kernel = new AppKernel('dev', true);
But not with the default configuration for the production enviroment ('prod',false).
I'm launching GAE server with this command:
google_appengine/dev_appserver.py --php_executable_path=/home/jon/php-sdk-gae/php-5.4.15/installdir/bin/php-cgi helloWorld/
I'm new in GAE, and I wonder Where can I find logs to get some more information about this error.
There is an uncaught exception in your production environment. Thats the reason for the http 500 error.
Let me quickly explain AppKernel::__construct
$kernel = new AppKernel($environment, $debug);
The first argument is the environment , the second one is the debug option.
If you set debug to true , symfony will try to catch exceptions and show you a nice stracktrace.
This covers the first and the third case where you don't get the http 500 error ( caused by an uncaught exception ).
$kernel = new AppKernel('prod', true);
$kernel = new AppKernel('dev', true);
Now you state the error is NOT thrown in dev environment with debug set to false.
$kernel = new AppKernel('dev', false);
This means in dev environment there is no exception.
Now you have to check the production log file to find out which exception has been thrown.
Use tail -f to see the live changes made to that file in your shell ( i.e. bash ) or if not available open the file in your editor and look for exceptions at the end.
tail -f app/logs/prod.log
In the symfony2 standard edition logfiles can be found at
app/logs/%kernel.environment%.log
... with %kernel.environment% being one of dev/prod/test
The problem is related with .htaccess file shipped with Symfony 2.2
I can use without any problem an application in symfony 2.0, and my application with Symfony 2.2 also works if I replace the web/.htaccess file shipped with Symfony 2.2 with the one shipped with Symfony 2.0
Maybe it is something related with the change made in order to avoid duplicate content (/app.php/something and /something), because since Symfony 2.2, /app.php redirects (301) the request.
I believe the problem is the lack of write support on the filesystem imposed by GAE. Also, symfony seems to rely on tempnam() function that's disabled in versions lower than 1.9.18 which is not public available at the moment I'm writing this.
There is also a problem with caching.
Maybe the problem is this, I've tried in localhost a project with developement version, all right. And when it's deployed to GAE it fails.
Maybe that helps.
http://www.ideato.it/planet-ideato/symfony2-su-google-app-engine/

Unable to set symfony project getting error on app.php

I have setup new project of symfony. app_dev.php/register is working good but when i switch to app.php/register then getting error
Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please e-mail us at [email] and let us know what you were doing when
this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
i have clear cache also but still getting this error. please give me solution i am in hurry because my project is goes final but now i am stucked here cannot publish it on live server
if you access it over app.php and get that error. you should try to setup debug modus of app.php file.
to do this you alter following line in the file web/app.php
$kernel = new AppKernel('prod', false);
to
$kernel = new AppKernel('prod', true);
this way symfony tells you what the problem is and i guess it has to do with the routing...

Categories