-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
RFC: Error Backtraces v2 #17056
Open
ericnorris
wants to merge
10
commits into
php:master
Choose a base branch
from
ericnorris:feat-error-backtrace-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−6
Open
RFC: Error Backtraces v2 #17056
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b9bd2f
rfc: error_backtraces_v2
ericnorris aa9c4f4
address second round of PR comments
ericnorris 47148c1
use `eval` instead of `new_oom.inc`
ericnorris a44ac31
fix tests that invoke PHP and thus don't inherit run-tests.php INI se…
ericnorris e843e06
clear backtrace when throwing an exception
ericnorris 2cd6c3f
address third round of PR comments
ericnorris aaa2443
move initialization of error_backtrace to handle NTS
ericnorris 5fd14ee
move `error_get_last` w/ fatal to separate test
ericnorris b1db022
rename `error_backtrace` global to `fatal_error_backtrace`
ericnorris 9f29e80
rename `fatal_error_backtrace` -> `last_fatal_error_backtrace`
ericnorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% confident in this being the right fix, though it is similar to the
EG(exception) = NULL
on L906 above. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems correct, this will clear the message for the next error. Do you have a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a sense, yes, since the existing
ext/soap
tests triggered the need for this, and once it was fixed the tests passed. On the other hand, it was only theext/soap
code that needs this. For example, throwing an exception that doesn't get caught in normal PHP won't trigger a double stack trace.I'm concerned this (clearing the trace when throwing an exception) may not be enough and there may be other "weird" error handling things in extensions that may also end up having a double stack trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to understand the problem exactly, it would be best to replicate in a new test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure how to replicate it in a test, since it has something to do with how
ext/soap
manipulateszend_error_cb
in C. I linked theext/soap
test that demonstrates this behavior in the commit message for this change: e843e06When I was debugging this, I noticed that
ext/soap
changes thezend_error_cb
here:php-src/ext/soap/soap.c
Line 548 in a091e52
It's then kind of hard to follow, but roughly speaking it ends up in here:
php-src/ext/soap/soap.c
Lines 1868 to 1871 in a091e52
If I remember correctly, the backtrace exists at this point, and then calling
zend_throw_exception_object(&fault);
andzend_bailout();
end up triggering the originalzend_error_cb
which prints out the exception and the backtrace, thus producing a double "Stack trace:" output.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having dealt a tiny bit with ext/soap my guess is the following:
SOAP Uses the bailout mechanisms (i.e. fatal errors) as its "exception" mechanism (as it predates exceptions existing in the language), and it now catches those to throw them as proper exceptions (although it sometimes also throws normal exceptions) which is probably the cause of this.
Refactoring ext/soap so it stops doing this is a long term goal of mine, but the extension is quite complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that makes sense. Do you think the above is an appropriate fix that might apply to other extensions doing stuff like this? I'm repeating myself, but I'm concerned that there might be other complex flows involving
zend_error_cb
that might run into related issues.Would it make more sense to do backtrace fetching only in
php_error_cb
? Perhaps that would solve the issue since presumablyEG(exception)
would be set and could be checked before fetching? Edit: though that would mean other extensions couldn't rely on the backtrace existing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, the only other extensions I see overloading
zend_error_cb
are debuggers and profilers. ext/soap is very special in this instance.