Skip to content
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

Merged
merged 11 commits into from
Apr 20, 2018
Merged

Apply other fix for #391 #576

merged 11 commits into from
Apr 20, 2018

Conversation

Jean85
Copy link
Collaborator

@Jean85 Jean85 commented Mar 21, 2018

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.

Copy link
Collaborator

@stayallive stayallive left a 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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

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.

Copy link
Collaborator Author

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...

@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 18, 2018

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?

if (function_exists('mb_convert_encoding')) {
mb_convert_encoding('string', 'UTF8');
}
if (function_exists('mb_convert_encoding')) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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..

Copy link
Collaborator Author

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.

Copy link
Contributor

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 :)

@@ -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');
Copy link
Contributor

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().

Copy link
Collaborator Author

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.

@@ -138,6 +138,8 @@ public function handleFatalError()
@$error['message'], 0, @$error['type'],
@$error['file'], @$error['line']
);

$this->client->useCompression &= PHP_VERSION_ID > 70000;
Copy link
Contributor

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 :)

Copy link
Collaborator Author

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!

@@ -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')) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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

@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 20, 2018

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;
Copy link
Contributor

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.

Copy link
Collaborator Author

@Jean85 Jean85 Apr 20, 2018

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.

@Jean85 Jean85 merged commit 61c862b into master Apr 20, 2018
@Jean85 Jean85 deleted the fix-575 branch April 20, 2018 16:01
@Jean85 Jean85 mentioned this pull request May 3, 2018
27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants