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
5 changes: 5 additions & 0 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ public function install()
$this->error_handler->registerExceptionHandler();
$this->error_handler->registerErrorHandler();
$this->error_handler->registerShutdownFunction();

if ($this->_curl_handler) {
$this->_curl_handler->registerShutdownFunction();
}

return $this;
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Raven/CurlHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct($options, $join_timeout = 5)
$this->requests = array();
$this->join_timeout = $join_timeout;

register_shutdown_function(array($this, 'join'));
$this->registerShutdownFunction();
}

public function __destruct()
Expand Down Expand Up @@ -69,6 +69,11 @@ public function enqueue($url, $data = null, $headers = array())
return $fd;
}

public function registerShutdownFunction()
{
register_shutdown_function(array($this, 'join'));
}

public function join($timeout = null)
{
if (!isset($timeout)) {
Expand Down
12 changes: 7 additions & 5 deletions test/Raven/phpt/fatal_reported_with_async.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ while (!file_exists($vendor.'/vendor')) {
require $vendor.'/test/bootstrap.php';
require $vendor.'/vendor/autoload.php';

$client = new \Raven_Client(array('curl_method' => 'async'));
$pendingEvents = \PHPUnit\Framework\Assert::getObjectAttribute($client, '_pending_events');
$curlHandler = \PHPUnit\Framework\Assert::getObjectAttribute($client, '_curl_handler');
$pendingRequests = \PHPUnit\Framework\Assert::getObjectAttribute($curlHandler, 'requests');
$dsn = 'https://user:password@sentry.test/123456';
$client = new \Raven_Client($dsn, array('curl_method' => 'async'));

$client->setSendCallback(function () {
echo 'Sending handled fatal error...' . PHP_EOL;
});

$client->install();

register_shutdown_function(function () use ($pendingEvents, $pendingRequests) {
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';
}
Expand Down