-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[3.0.0]Seg fault on php5 when forwarding from beforeException #12154
Comments
Yea but what is weird it works on php 7 though. |
Confirmed issue as well. Backtrace
Backtrace when built with zephir builddev
|
There are actually 2 bugs.
Here is the test script which outlines the 2 bugs. Adjust the commented sections in the 3 cases in the index.php <?php
/**
* IndexController
*/
class IndexController extends \Phalcon\Mvc\Controller
{
public function initialize()
{
$this->getDI()->getShared('view')->disable();
}
public function indexAction()
{
echo 'Index Action <br />';
throw new Exception('Something happened');
}
public function errorAction()
{
echo 'Error Action <br />';
}
}
/**
* Dispatcher ExceptionHandler
*/
class ExceptionHandler extends \Phalcon\Mvc\User\Plugin
{
public function beforeException(\Phalcon\Events\Event $event, \Phalcon\DispatcherInterface $dispatcher, \Exception $exception)
{
echo 'ExceptionHandler::beforeException() - ' . $exception->getMessage() . '<br />';
////////////////////////////////////////////////////////
// Case 1:
////////////////////////////////////////////////////////
// return false;
// **Output** (OK)
// Index Action
// ExceptionHandler::beforeException() - Something happened
////////////////////////////////////////////////////////
// Case 2 - Empty return or nothing at all
////////////////////////////////////////////////////////
// return;
// **Output** (Exception handler gets thrown twice)
// Index Action
// ExceptionHandler::beforeException() - Something happened
// ExceptionHandler::beforeException() - Something happened
// Fatal error: Uncaught exception 'Exception' with message 'Something happened' in /var/www/public/index.php:18 Stack trace: #0 [internal function]: IndexController->indexAction() #1 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(IndexController), 'indexAction', Array) #2 [internal function]: Phalcon\Dispatcher->_dispatch() #3 [internal function]: Phalcon\Dispatcher->dispatch() #4 /var/www/public/index.php(87): Phalcon\Mvc\Application->handle() #5 {main} thrown in /var/www/public/index.php on line 18
// The beforeException gets called again (resulting 2x) because we're not marked
// as finished so the exception gets thrown up the stack
// https://github.com/phalcon/cphalcon/blob/master/phalcon/dispatcher.zep#L595
// **Expected Output**
// Index Action
// ExceptionHandler::beforeException() - Something happened
// Fatal error: Uncaught exception 'Exception' with message 'Something happened' in /var/www/public/index.php:18 Stack trace: #0 [internal function]: IndexController->indexAction() #1 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(IndexController), 'indexAction', Array) #2 [internal function]: Phalcon\Dispatcher->_dispatch() #3 [internal function]: Phalcon\Dispatcher->dispatch() #4 /var/www/public/index.php(87): Phalcon\Mvc\Application->handle() #5 {main} thrown in /var/www/public/index.php on line 18
////////////////////////////////////////////////////////
// Case 3:
////////////////////////////////////////////////////////
// $dispatcher->forward(['action' => 'error']);
// return false;
// **Output** (SIGFAULT - Combination of forward + return false)
// **Expected Output**
// Index Action
// ExceptionHandler::beforeException() - Something happened
// Error Action
}
}
////////////////////////////////////////////////////////
// Bootstrap
////////////////////////////////////////////////////////
$di = new \Phalcon\Di\FactoryDefault();
$di->setShared('view', function() {
return new \Phalcon\Mvc\View();
});
$di->setShared('dispatcher', function() {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('dispatch:beforeException', new ExceptionHandler());
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
$application = new \Phalcon\Mvc\Application();
$application->setEventsManager(new \Phalcon\Events\Manager());
$application->setDI($di);
echo $application->handle()->getContent(); |
There's a 2 issues for why this isn't working. The primary issue is there exists a core Zephir bug with multiple try/catch blocks. The resulting Zephir code currently compiles bad c code for the JUMP frames as a result of: https://github.com/phalcon/zephir/blob/master/Library/Call.php#L676 public function addCallStatusOrJump(CompilationContext $compilationContext)
{
$compilationContext->headersManager->add('kernel/fcall');
if (!$compilationContext->insideTryCatch) {
$compilationContext->codePrinter->output('zephir_check_call_status();');
} else {
$compilationContext->codePrinter->output(
'zephir_check_call_status_or_jump(try_end_' . $compilationContext->insideTryCatch . ');'
// ^^currentTryCatch
);
}
} The outputting of the JUMP call always results in @andresgutierrez or @sergeyklay - Can you guys update zephir with above fix^^ Once that's fixed in Zephir, the double dispatch error can be fixed by pulling out the commit that wraps the entire dispatch loop in a separate try/catch. I'm working on a PR that will fix the double error handling while still ensuring proper bubbling of exceptions. |
Could you please check 3.0.x branch? git clone [email protected]:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x
# Use latest Zephir here from master branch
zephir fullclean
zephir build |
exceptions, and improved documentation/test-suite for dispatcher components [phalcon#12154](phalcon#12154), [phalcon#11819](phalcon#11819)
Fixed in the |
Expected and Actual Behavior
Should return test, but it doesn't, there is just seg fault when accessing just index page(
/
)On php7 it works though.
Backtrace - http://pastebin.com/jD5GQJaJ
Github repo - https://github.com/Jurigag/phalcon-segfault-before-forward
Details
The text was updated successfully, but these errors were encountered: