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

Crash dumps with Volt alwaysRecompileView=TRUE #1949

Closed
icex opened this issue Jan 30, 2014 · 11 comments
Closed

Crash dumps with Volt alwaysRecompileView=TRUE #1949

icex opened this issue Jan 30, 2014 · 11 comments

Comments

@icex
Copy link

icex commented Jan 30, 2014

Hi,

We're getting a lot of crash dumps. I've tried with cphalcon 1.2.5/1.2.6/1.3.0, it's the same issue.
I think it's the 'alwaysRecompileView' => TRUE. With FALSE it works just fine. This happens when we stress the server with many concurent requests to check the performance. Probably a IO thing with writing files.
#0 lex_scan (zendlval=0x7fff8ec82bc8) at Zend/zend_language_scanner.c:1091
#1 0x0000000000734ef0 in zendlex (zendlval=0x7fff8ec82bc0) at /usr/local/src/php-5.5.7/Zend/zend_compile.c:6749
#2 0x000000000071d753 in zendparse () at /usr/local/src/php-5.5.7/Zend/zend_language_parser.c:3436
#3 0x0000000000729e15 in compile_file (file_handle=0x7fff8ec85190, type=) at Zend/zend_language_scanner.l:588
#4 0x0000000000595391 in phar_compile_file (file_handle=0x7fff8ec85190, type=8) at /usr/local/src/php-5.5.7/ext/phar/phar.c:3383
#5 0x00007f2a531d4474 in xc_compile_file (h=0x7fff8ec85190, type=8) at /usr/local/src/xcache-3.1.0/mod_cacher/xc_cacher.c:2196
#6 0x00007f2a50cb07cc in phalcon_internal_require () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#7 0x00007f2a50d3729f in zim_Phalcon_Mvc_View_Engine_Volt_render () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#8 0x00007f2a50cbb6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#9 0x00007f2a50cbbeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#10 0x00007f2a50e0996d in zim_Phalcon_Mvc_View__engineRender () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#11 0x00007f2a50cbb6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#12 0x00007f2a50cbbeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#13 0x00007f2a50deac9b in zim_Phalcon_Mvc_View_render () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#14 0x00007f2a50cbb6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#15 0x00007f2a50cbbeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#16 0x00007f2a50d2a3a3 in zim_Phalcon_Mvc_Application_handle () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#17 0x00000000007d91c2 in zend_do_fcall_common_helper_SPEC (execute_data=) at /usr/local/src/php-5.5.7/Zend/zend_vm_execute.h:552
#18 0x00000000007ca9b0 in execute_ex (execute_data=0x7f2a61bff708) at /usr/local/src/php-5.5.7/Zend/zend_vm_execute.h:363
#19 0x0000000000756da9 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/local/src/php-5.5.7/Zend/zend.c:1320
#20 0x00000000006f8c19 in php_execute_script (primary_file=0x7fff8ec8a9e0) at /usr/local/src/php-5.5.7/main/main.c:2489
#21 0x000000000080f9b2 in main (argc=, argv=) at /usr/local/src/php-5.5.7/sapi/fpm/fpm/fpm_main.c:1933

(gdb)

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@ghost
Copy link

ghost commented Jan 30, 2014

The crash happens in Zend/zend_language_scanner.c and it is likely to be a bug in the Zend Engine rather than in Phalcon.

Could you please turn off XCache and see if the problem persists?

@icex
Copy link
Author

icex commented Jan 30, 2014

Sorry, I forgot to enable crash dumps again. With xcache off:

#0 lex_scan (zendlval=0x7ffffe7d6058) at Zend/zend_language_scanner.c:1091
#1 0x0000000000734ef0 in zendlex (zendlval=0x7ffffe7d6050) at /usr/local/src/php-5.5.7/Zend/zend_compile.c:6749
#2 0x000000000071d753 in zendparse () at /usr/local/src/php-5.5.7/Zend/zend_language_parser.c:3436
#3 0x0000000000729e15 in compile_file (file_handle=0x7ffffe7d73e0, type=) at Zend/zend_language_scanner.l:588
#4 0x0000000000595391 in phar_compile_file (file_handle=0x7ffffe7d73e0, type=8) at /usr/local/src/php-5.5.7/ext/phar/phar.c:3383
#5 0x00007f00f28337cc in phalcon_internal_require () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#6 0x00007f00f28ba29f in zim_Phalcon_Mvc_View_Engine_Volt_render () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#7 0x00007f00f283e6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#8 0x00007f00f283eeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#9 0x00007f00f298c96d in zim_Phalcon_Mvc_View__engineRender () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#10 0x00007f00f283e6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#11 0x00007f00f283eeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#12 0x00007f00f296d521 in zim_Phalcon_Mvc_View_render () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#13 0x00007f00f283e6d0 in phalcon_call_method_vparams () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#14 0x00007f00f283eeb7 in phalcon_call_method_params () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#15 0x00007f00f28ad3a3 in zim_Phalcon_Mvc_Application_handle () from /usr/local/lib/php/extensions/no-debug-non-zts-20121212/phalcon.so
#16 0x00000000007d91c2 in zend_do_fcall_common_helper_SPEC (execute_data=) at /usr/local/src/php-5.5.7/Zend/zend_vm_execute.h:552
#17 0x00000000007ca9b0 in execute_ex (execute_data=0x7f010355d470) at /usr/local/src/php-5.5.7/Zend/zend_vm_execute.h:363
#18 0x0000000000756da9 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/local/src/php-5.5.7/Zend/zend.c:1320
#19 0x00000000006f8c19 in php_execute_script (primary_file=0x7ffffe7dcc30) at /usr/local/src/php-5.5.7/main/main.c:2489
#20 0x000000000080f9b2 in main (argc=, argv=) at /usr/local/src/php-5.5.7/sapi/fpm/fpm/fpm_main.c:1933
(gdb) q
[root@mpossy dump]# php -i | grep xcache
[root@mpossy dump]#

@ghost
Copy link

ghost commented Jan 30, 2014

The crash still happens in the same place, inside Zend lexic analyzer.

Could you please try to compile Phalcon in debug mode:

phpize
./configure "CFLAGS=-O0 -g3"
make
sudo make install

and then generate the backtrace with bt full?

@icex
Copy link
Author

icex commented Jan 30, 2014

Here you go:
http://pastebin.com/QPva7359

@ghost
Copy link

ghost commented Jan 30, 2014

Thanks, could you please post /home/mpossy/app/config/../../cache/_home_mpossy_app_views_merchant_index.volt.php as well?

Aslo, if you run

<?php
require '/home/mpossy/app/config/../../cache/_home_mpossy_app_views_merchant_index.volt.php';
?>

does PHP crash?

@icex
Copy link
Author

icex commented Jan 30, 2014

http://pastebin.com/vPbk0WFd

It doesn't crash because it fails to do anyting without phalcon. "Fatal error: Using $this when not in object context"

@ghost
Copy link

ghost commented Jan 30, 2014

OK, could you please try to apply this patch:

diff --git a/ext/mvc/view/engine/volt.c b/ext/mvc/view/engine/volt.c
index 39545d6..a4f33ab 100644
--- a/ext/mvc/view/engine/volt.c
+++ b/ext/mvc/view/engine/volt.c
@@ -245,10 +245,24 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){
                );
        }

-       if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) {
-               RETVAL_FALSE;
-               RETURN_MM();
+       {
+               zend_file_handle *pfile;
+               zend_file_handle file = {0};
+
+               convert_to_string(compiled_template_path);
+
+               file.filename      = Z_STRVAL_P(compiled_template_path);
+               file.opened_path   = NULL;
+               file.free_filename = 0;
+               file.type          = ZEND_HANDLE_FILENAME;
+               pfile              = &file;
+
+               if (FAILURE == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, pfile)) {
+                       RETVAL_FALSE;
+                       RETURN_MM();
+               }
        }
+
        if (PHALCON_IS_TRUE(must_clean)) {
                PHALCON_INIT_VAR(contents);
                phalcon_ob_get_contents(contents TSRMLS_CC);

then rebuild the source:

php build/gen-build.php

rebuild Phalcon and see if crashes still happen?

This will use Zend's require instead of phalcon_require.

@icex
Copy link
Author

icex commented Jan 31, 2014

Hi,

Sorry for the late reply. It doesn't compile. maybe a missing if clause?

@tsnyder91
Copy link

I experienced the same issue. I compiled with the following

 //if (phalcon_require(Z_STRVAL_P(compiled_template_path) TSRMLS_CC) == FAILURE) {
        zend_file_handle *pfile;
               zend_file_handle file = {0};

              convert_to_string(compiled_template_path);

               file.filename      = Z_STRVAL_P(compiled_template_path);
               file.opened_path   = NULL;
               file.free_filename = 0;
               file.type          = ZEND_HANDLE_FILENAME;
               pfile              = &file;

               if (FAILURE == zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 1, pfile)) {
                       RETVAL_FALSE;
                       RETURN_MM();
               }

        //}

And still had the same problem. I believe it is caused by the generation of the file earlier in this file around line 225, It gets compiled and created but by the time it gets executed another thread is in the middle of modifying this same file and is corrupt. i'm not good with c yet but there appears to need to be a way to add a lock to the file once its created and then released after its executed to ensure the thread that generated the file is getting the same file it generated.

@andresgutierrez
Copy link
Contributor

Could you please try again using Phalcon 2 or close this issue as 1.3.x is no longer supported

@tobispace
Copy link

tobispace commented Dec 25, 2016

We experienced the same issue, see:
https://forum.phalconphp.com/discussion/14869/php5fpm-on-nginx-crash-zendzendlanguagescannerc-no-such-file-or-

How to reproduce: set PHP-FPM with option pm.max_children with a value greater than 1 (2, 10, 500...) and try to open a lot of pages in the application at the same time from at least two clients (in order to force PHP-FPM to serve more than 1 request at the same time). Volt must be configured with compileAlways=true.

Some of these requests will fail, causing Nginx to throw 502 Error. The core dump will contain the error:

Zend/zend_language_scanner.c: no such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants