-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Fatal errors are not recorded with the curl method async #391
Comments
Although some work was done on this last year, I believe this is still an issue, see #552 (comment) |
Isn't BTW yes, this is surely related to #552 @nokitakaze IIRC you wrote this part, what do you think? |
I'm afraid I don't know. This case must be tested in separate process to test the behaviour. |
…d async very inelegant, but if we call onShutdown() then error could be logged (if other logic allows it :)
I pushed a commit to demonstrate what needs to happen during the fatal error shutdown. |
Hmm not sure off the top of my head, if you had access to $client->_curl_handler->requests you could see if the requests were sent off? |
here's code to reproduce the problem, just need a way to detect it: <?php
include './vendor/autoload.php';
ini_set('memory_limit', '8M');
$client = new Raven_Client('...', ['curl_method' => 'async']);
$client->install();
while (TRUE) {
$a[] = 'b';
} |
I think that the only way to detect it would be adding first an other exception handler which could output the result... I'll try that now. |
I cannot reproduce the issue, at least not under PHP 7. <?php
include '../vendor/autoload.php';
$dsnPublicSite = 'https://*****:******@sentry.io/*****';
$client = new Raven_Client($dsnPublicSite, ['curl_method' => 'async']);
$client->install();
ini_set('memory_limit', '8M');
while (TRUE) {
$a[] = 'b';
} ... and this is the correct result: I think that curl is called correctly because it's registered as a shutdown function here: sentry-php/lib/Raven/CurlHandler.php Line 32 in 7843378
|
I've just tested it under PHP 5.6 and I can reproduce the issue, but my test is still green... Don't know why! [EDIT] This is my test: e4fde16 |
Well, I can't get it to work on PHP 7.1, presumably because Raven_ErrorHandler registers its shutdown function last, so when it runs (firing off the last exception message), join() has already been called. |
Your test is noting that join() was called, but it needs to be called again after handleFatalError() is called. |
* Try to recreate a regression PHPT tests for async sending of fatal errors * Refactor PHPT regression test to check correctly for bug * Apply fix for #391: culprit was bad autoloading during fatal handling under PHP > 7 * Add PHPT tests to PHPUnit config to be run on Travis (cherry picked from commit 92db2d9)
#575 merged, can you test if this solves this issue? |
I added some echo statements in the shutdown-related methods to make sure I'm not crazy, here's what I see:
So handleFatalError() is still running last, and there is no additional call to join() after that. The order makes sense because that's the order that register_shutdown_function() is called (the Client makes its own additional call to join). |
I had to tweak the test to have an actual working DSN, otherwise it seems like requests didn't queue up? Also passed a reference to the client into the anonymous shutdown function rather than copying the variables. This gives me "There are still queued request inside the Curl Handler": <?php
$client = new \Raven_Client('ACTUAL WORKING DSN HERE', array('curl_method' => 'async'));
$client->setSendCallback(function () {
echo 'Sending handled fatal error...' . PHP_EOL;
});
$client->install();
register_shutdown_function(function () use (&$client) {
$pendingEvents = \PHPUnit\Framework\Assert::getObjectAttribute($client, '_pending_events');
$curlHandler = \PHPUnit\Framework\Assert::getObjectAttribute($client, '_curl_handler');
$pendingRequests = \PHPUnit\Framework\Assert::getObjectAttribute($curlHandler, 'requests');
if (! empty($pendingEvents)) {
echo 'There are pending events inside the client';
}
if (empty($pendingRequests)) {
echo 'Curl handler successfully emptied';
} else {
echo 'There are still queued request inside the Curl Handler';
}
});
ini_set('memory_limit', '8M');
while (TRUE) {
$a[] = 'b';
} |
) * Improve regression test for #575 * Apply final fix for #575 and #391 * Refactor PHPT test to avoid triggering autoloader during shutdown * Trigger early autoload for the gzcompress function * Disable zip compression while handling a fatal under PHP 5.x * Trigger other autoloads * Avoid false failure in regression test * Ignore failures under PHP 5.4/5.5 * Move inspection of client state inside the shutdown function * Apply review fixes
Thanks everyone for helping out 👍 We believe this issue should be fixed in 1.9.0 that was just released, if there is still an issue please reopen this issue. |
I have a related PR at #613 to provide a method for registering the async shutdown function. This is required by any custom setups of the client that don't call install() |
Sentry flushes the unsent messages and calls curl join in the onShutdown method, which is correctly registered to run on shutdown.
However, fatal errors are logged on the ErrorHandler shutdown callback, which is registered after
onShutdown
. (onShutdown
is registered on the Client constructor, anderror_handler->registerShutdownFunction
is call after you build the Client).The end result is that a Fatal error gets recorded internally, but it's not send as
onShutdown
has already been called.You need to make sure
onShutdown
runs after all other shutdown handlers.The text was updated successfully, but these errors were encountered: