-
-
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
Apply other fix for #391 #576
Conversation
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.
👍 looks good although Travis doesn't like it...
@@ -21,7 +22,7 @@ $client->setSendCallback(function () { | |||
|
|||
$client->install(); | |||
|
|||
register_shutdown_function(function () use ($pendingEvents, $pendingRequests) { | |||
register_shutdown_function(function () use (&$pendingEvents, &$pendingRequests) { |
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.
You are using a reference for &$pendingRequests
but I think this is still pointing at the list of requests when the script starts rather than actual client state?
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.
Nope, it's getting the actual client state at the end, since the test was failing until I applied 6eb54f2
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 just double-checked and no, the test will pass even if I break the code such that there are still pending requests. $pendingRequests is a reference to the initial state of there being no pending requests, not the actual client's pending requests.
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.
Damn you're right once again 😄
Ok, so is 01a26d3 enough to fix it? It seems to fail now if I comment stuff inside the client...
I've decided to avoid fixing this under PHP 5.4 and 5.5. Those are long gone EOLed versions, and the issue is located in the JSON serialization of the exception during fatal error handling, so it's nearly impossible to fix it now. I think this PR should be merged anyway, so we at least have some value in all the other use cases, and we can bring these regression tests along into 2.x. Can you re-review it? |
lib/Raven/Client.php
Outdated
if (function_exists('mb_convert_encoding')) { | ||
mb_convert_encoding('string', 'UTF8'); | ||
} | ||
if (function_exists('mb_convert_encoding')) { |
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.
You have repeated these lines twice; was that intentional?
Also, what does mb_detect_encoding() and mb_convert_encoding() have to do with autoloading?
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.
The fact that they are there twice is a mistake, I'll delete them ASAP.
As for the rest, functions are autoloaded too, so I need to trigger that in advance, to avoid triggering the autoload during the fatal error handling phase, where it would crash hard.
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.
Oh interesting! Where can I read about autoload for functions? I thought you couldn't autoload functions..
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.
Sorry, I used the wrong term. Functions are not "autoloaded" like classes, but still they are searched by namespace and loaded with a similar logic. So calling a function for the first time only during error handling makes everything crash under PHP 5, and that's why I'm forced to do this workaround and call them at least once before proceeding.
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.
eesh! I had never seen a requirement to call functions first, but happily I don't use PHP 5 anymore so can't dig into this :)
lib/Raven/Client.php
Outdated
@@ -195,6 +200,7 @@ public function __construct($options_or_dsn = null, $options = array()) | |||
$this->context = new Raven_Context(); | |||
$this->breadcrumbs = new Raven_Breadcrumbs(); | |||
$this->_shutdown_function_has_been_set = false; | |||
$this->useCompression = function_exists('gzcompress') && extension_loaded('zip'); |
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.
Why does zip extension matter here? Zip extension doesn't provide gzcompress().
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 older PHP versions (5.4 to 5.6, see this build of 68eb97c, which is the commit before ce2b5b5 which introduced this fix) the zip extension is not always present... I tried to not check the extension but it wasn't working.
lib/Raven/ErrorHandler.php
Outdated
@@ -138,6 +138,8 @@ public function handleFatalError() | |||
@$error['message'], 0, @$error['type'], | |||
@$error['file'], @$error['line'] | |||
); | |||
|
|||
$this->client->useCompression &= PHP_VERSION_ID > 70000; |
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.
Maybe it's just me, but using bitwise operator on boolean feels wrong to me :)
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.
Wops! That works by mere coincidence I think 😅 fixing now!
test/Raven/Tests/ClientTest.php
Outdated
@@ -2072,7 +2072,7 @@ public function testEncode() | |||
$this->assertRegExp('_^[a-zA-Z0-9/=]+$_', $value, 'Raven_Client::encode returned malformed data'); | |||
$decoded = base64_decode($value); | |||
$this->assertInternalType('string', $decoded, 'Can not use base64 decode on the encoded blob'); | |||
if (function_exists("gzcompress")) { | |||
if (function_exists('gzcompress') && extension_loaded('zip')) { |
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.
Another case where I think zip extension doesn't matter?
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 the same stuff, but on the other side, the test... I'll try to change this and see if it still works
Build is green, all is right! 🎉 Thanks for the multiple, very thorough reviews @mfb! |
@@ -138,6 +138,8 @@ public function handleFatalError() | |||
@$error['message'], 0, @$error['type'], | |||
@$error['file'], @$error['line'] | |||
); | |||
|
|||
$this->client->useCompression = $this->client->useCompression && PHP_VERSION_ID > 70000; |
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.
Would be good to comment why PHP version matters here.
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.
Well, now we have a regression test with this PR, so removing that check will make the test fail under PHP 5.
Basically, the reason is that under PHP 7 handling errors is no more a "special place" (thanks to \Throwable
probably), so autoloading and other normal stuff work there too.
This implements the regression suggested in #391 (comment) and should finally fix the issue with fatals + curl async.
Thanks again to @mfb for helping me debugging this issue.