-
Notifications
You must be signed in to change notification settings - Fork 17
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
[Bug]: Infinite recursion with unhandled exception due to restore_exception_handler #81
Comments
I've got a simple workaround running, by extending I still need to test this further, I'm just getting started with Wonolog. But if this works and it's in your interest, I can draft up a PR. |
Thanks @gaambo It never worked restoring the previous handler, but before PHP 8.3, it did not trigger an infinite loop either. In the comment in the official docs you linked, where the exception is re-thrown, there is no mention of an endless loop because that is a new thing.
This is a bug, but it is only visible on PHP 8.3, which we are yet testing for... If you can do a PR with the fix, I'm definitively interested, but I would like to avoid the requirement that |
Moreover, it looks like you're using Wonolog v1. You should look into v2 for more modern PHP support, or even in the upcoming v3 |
It might be something like this: https://3v4l.org/jme3m The |
Very interesting finding, thank you @gmazzap.
That is just for my custom implementation for Php_Error_Controller, because the setup happens in the constructor. If it's in the framework, that's not required. I also just wanted to share the workaround for anyone coming here.
I wasn't sure about their stability and therefore stuck to v1. But we'll probably want to use a 3rd party handler as well that requires at least monolog v2, so we'll probably update soon. Should I create a PR for v1, v2 or v3? 😬 |
Having the same problem. Is a fix going to be implemented for this? |
Description of the bug
I'm running into an infinite recursion when throwing an exception somehwere.
The
PhpErrorController:on_exception
exception handler is correctly called and logs the exception, but it then callsrestore_exception_handler
and re-throws the Exception which triggers the same function again.According to a comment in the PHP docs:
Therefore it runs the same method over and over again.
Reproduction instructions
init
)on_exception
method get called over and over againExpected behavior
In my case I just wanted to test the logging by manually throwing an exception. But when a real one throws, it loggs a huge amount of the same message and runs into fatal error with "Maximum call stack size".
I found out that you can use
set_exception_handler(null);
to reset it to the PHP defaults exception handler. Then theon_fatal
will be called, because the exception is unhandled.Another possibility would be to save the return-value of
set_exception_handler
(= the previous one) inController::log_php_errors
and restore to it later.Environment info
Relevant log output
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: