cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

502 error with Phalcon 2.0 on Nginx and PHP 5.6, Ubuntu x64 14.04

Open Swader opened this issue 12 years ago • 39 comments

Using this tutorial but upgrading the box and using PHP 5.6, the end result is yet another this:

2014/09/01 00:37:31 [error] 17615#0: *16 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.0.2.2, server: test.app, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "test.app:8000"
2014/09/01 00:41:04 [error] 17615#0: *26 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.0.2.2, server: test.app, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "test.app:8000"

The error happens when the code reaches this part in bootstrap.php:

            return $application->handle()->getContent();

I can still die() before that line and it'll render.

Note that I have disabled Xdebug as per @duythien's advice and set the debug flag to 1 in config, no effect.

Phalcon is successfully installed with version 2.0.0a and Zephir 0.4.6a.

If I can help with providing more information, let me know.


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

Swader avatar Sep 01 '14 01:09 Swader

@phalcon @niden any way to get a debug dump straight out of Phalcon? Nginx error logs are useless, and I can't really go into PhApplication to debug line by line, especially since Xdebug has to be off too.

Swader avatar Sep 01 '14 14:09 Swader

@Swader you can move into index file, then running

php index.php

duythien avatar Sep 01 '14 17:09 duythien

As @duythien said:

cd /path/to/website/public
gdb php
run index.php
bt full

ghost avatar Sep 01 '14 17:09 ghost

This is the output:

(gdb) run index.php
Starting program: /usr/bin/php index.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00000000006b1a05 in ?? ()
(gdb)

Swader avatar Sep 01 '14 18:09 Swader

It seems you have to compile Phalcon in debug mode, please compile it as follows:

git clone http://github.com/phalcon/cphalcon
git checkout 2.0.0
cd ext
sudo ./install-test

ghost avatar Sep 01 '14 18:09 ghost

@phalcon done and rebooted it all, but the result is exactly the same on all fronts. Where should I be seeing some more information about problems?

Swader avatar Sep 01 '14 18:09 Swader

Could you try compiling again? Please pull changes down from the 2.0.0 branch

ghost avatar Sep 01 '14 19:09 ghost

This makes me feel much better, because I am getting the same thing, but running v5.5.16 in my local Homestead environment. Thought I was just an idiot! Was going to try and run the tests on the v2 branch and got this output...

vagrant@homestead:/vagrant/cphalcon/php-tests/tests$ phpunit
PHPUnit 4.1.3 by Sebastian Bergmann.

Configuration read from /vagrant/cphalcon/php-tests/tests/phpunit.xml

................Segmentation fault (core dumped)

At which point, I tried loading up a local phalcon project and saw the 502 error. I do not have gdb installed, so... cannot confirm my output to @Swader's.

I will also add, when compiling Phalcon v2.0.0 branch, with Zephir, I this is the output...

Warning: Class "APCIterator" does not exist at compile time  in /vagrant/cphalco
n/phalcon/cache/backend/apc.zep on 222 [nonexistent-class]

           apc = new \APCIterator("user", prefixPattern);
        ------------------------------------------------^


Warning: Unreachable code in /vagrant/cphalcon/phalcon/dispatcher.zep on 581 [un
reachable-code]

           if typeof eventsManager == "object" {
        ---------------------------------------^


Warning: Unreachable code in /vagrant/cphalcon/phalcon/dispatcher.zep on 596 [un
reachable-code]

           if method_exists(handler, "afterExecuteRoute") {
        --------------------------------------------------^


Warning: Possible attempt to use non-object in "new" operator in /vagrant/cphalc
on/phalcon/mvc/model.zep on 584 [non-valid-new]

           let hydrate = new \stdclass();
        --------------------------------^


Warning: Variable "columnMap" declared but not used in Phalcon\Mvc\Model\MetaDat
a::_initialize in /vagrant/cphalcon/phalcon/mvc/model/metadata.zep on 94 [unused
-variable]

           dependencyInjector, columnMap, keyName, prefixKey;
        --------------------------------^


Warning: Function "phalcon_orm_singlequotes" does not exist at compile time in /
vagrant/cphalcon/phalcon/mvc/model/query.zep on 511 [nonexistent-function]

               let escapedValue = phalcon_orm_singlequotes(value);
        ---------------------------------------------------------^


Warning: Variable 'sqlJoinConditions' was assigned for the first time in conditi
onal branch, consider initialize it at its declaration in /vagrant/cphalcon/phal
con/mvc/model/query.zep on 935 [conditional-initialization]

          ];
        --^


Compiling...
Installing...
Extension installed!
Don't forget to restart your web server

The second warning is a bit troubling, since it deals with the eventsManager() within the Dispatcher class. Honestly, have not dug into that. This is just my system though.

@Swader, do you see the same warnings when compiling Phalcon?

@phalcon I added the cphalcon repo as an upstream remote, just now, and it states, when performing git pull upstream 2.0.0 that everything is up-to-date

Output of git pull to remote v2 branch

\vagrant@homestead:/vagrant/cphalcon$ git pull upstream 2.0.0
From https://github.com/phalcon/cphalcon
 * branch            2.0.0      -> FETCH_HEAD
Already up-to-date.

Hope that I did not induce information overload... :(

unisys12 avatar Sep 01 '14 19:09 unisys12

@unisys12 Please try running the tests with --debug flag to see which test is segfaulting:

$ phpunit --debug

ghost avatar Sep 01 '14 20:09 ghost

Sorry for the delay... Here is the output at the line of the segfault

Starting test 'Phalcon\Test\Http\Request\UnitTest::testInput'.
Segmentation fault (core dumped)

unisys12 avatar Sep 01 '14 20:09 unisys12

It's passing on my machine:

$ phpunit --debug
PHPUnit 4.2.0 by Sebastian Bergmann.

Configuration read from /home/andres/cphalcon/php-tests/tests/phpunit.xml

Starting test 'Phalcon\Test\Escaper\UnitTest::testEscapeHtml'.
.
Starting test 'Phalcon\Test\Acl\Resource\UnitTest::testAclResourceName'.
.
Starting test 'Phalcon\Test\Acl\Resource\UnitTest::testAclResourceNameDescription'.
.
Starting test 'Phalcon\Test\Acl\Role\UnitTest::testAclRoleNameEmptyDescription'.
.
Starting test 'Phalcon\Test\Acl\Role\UnitTest::testAclRoleNameDescription'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testInstanceOf'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testHeaderGetEmpty'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testHeaderGet'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testIsAjaxDefault'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testIsAjax'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testGetSchemeDefault'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testGetScheme'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testIsSecureRequestDefault'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testIsSecureRequest'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testGetServerAddressDefault'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testGetServerAddress'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testInput'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testHttpHost'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testMethod'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testAcceptableContent'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testAcceptableCharsets'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testAcceptableLanguage'.
.
Starting test 'Phalcon\Test\Http\Request\UnitTest::testClientAddress'.
.
Starting test 'Phalcon\Test\Security\UnitTest::testHash'.
.

Time: 5.79 seconds, Memory: 3.25Mb

OK (24 tests, 86 assertions)

Anyway I can access your machine?

ghost avatar Sep 01 '14 20:09 ghost

I don't know. Might be able to do something over on a G+ hang or some thing. Let me try bring up a new environment and starting from scratch. Maybe do something outside of Homestead, maybe use Puphpet to quickly get something up and running. I will let you know then, if I cannot isolate this issue further.

I would like to prove or disprove weather @Swader and I both have the same issue. Since he and I both are Homestead users, I think it would be best if I explore that first.

Well let you know

unisys12 avatar Sep 01 '14 20:09 unisys12

I'll try to set up a Vagrant machine with Phalcon 2 as the article describes

ghost avatar Sep 01 '14 21:09 ghost

After pulling the latest changes and recompiling without zephir, as you described above, with install-test, everything seems to be working fine. Tests in the php-tests/tests folder of cphalcon are passing, too.

Swader avatar Sep 01 '14 21:09 Swader

@unisys12 did you try the new version? Does it work for you too now?

Swader avatar Sep 02 '14 00:09 Swader

@Swader No, unfortunately it did not resolve my issue. So I think we may be experiencing different issues. They may lead to same end 502 error page but different cause.

I made a fresh clone into an existing puphpet environment running php v5.5.16. Zephir was already installed in this environment, but I installed it using the methods outlined above (using sudo ./install-test). But still, the same tests fail at the same point and get the same 502 error when accessing the index page.

One thing that I did find was: When instantiating a micro app, as long as I do not config a view and return items directly from a closure, everything seemingly works fine. Similar to this thread on the forums - http://forum.phalconphp.com/discussion/3297/php-5-6-0-gives-an-error-get-failed-net-err-empty-response-

unisys12 avatar Sep 02 '14 00:09 unisys12

How about if you follow the instructions from the article in the original post of this issue? Can you get the phalcon website to run locally on 2.0?

Swader avatar Sep 02 '14 00:09 Swader

@Swader Nope, do dice.

I installed gdb and took a stab at what @phalcon and @duythien was working towards earlier in your issue. This was the output

(gdb) run index.php
Starting program: /usr/bin/php index.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe9ded700 (LWP 4321)]
[Thread 0x7fffe9ded700 (LWP 4321) exited]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5088b77 in xdebug_build_fname (edata=0x7fffffffa630, tmp=0x13cbe30)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug_stack.c:918
918     /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug_stack.c: No such file or
directory.
(gdb) bt full
#0  0x00007ffff5088b77 in xdebug_build_fname (edata=0x7fffffffa630,
    tmp=0x13cbe30)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug_stack.c:918
        fname = 0x7fffffffccdf ""
#1  xdebug_add_stack_frame (zdata=zdata@entry=0x7fffffffa630, op_array=0x0,
    type=type@entry=1)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug_stack.c:1039
        edata = 0x7fffffffa630
        opline_ptr = 0x7ffff7fa9320
        tmp = 0x13cbe30
        cur_opcode = <optimized out>
        param = <optimized out>
        i = 0
        aggr_key = 0x0
        aggr_key_len = 0
#2  0x00007ffff5079534 in xdebug_execute_internal (
    current_execute_data=0x7fffffffa630, fci=0x7fffffffa7b0,
    return_value_used=1)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug.c:1520
        edata = 0x7fffffffa630
        fse = <optimized out>
        cur_opcode = <optimized out>
        do_return = 0
        function_nr = 0
        restore_error_handler_situation = 0
        tmp_error_cb = 0x0
#3  0x00000000006c348b in zend_call_function ()
No symbol table info available.
#4  0x00007fffeaae8b19 in zephir_call_user_function ()
   from /usr/lib/php5/20121212/phalcon.so
No symbol table info available.
#5  0x00007fffeaaf06af in zephir_call_func_aparams ()
   from /usr/lib/php5/20121212/phalcon.so
No symbol table info available.
#6  0x00007fffeaae2295 in zim_Phalcon_Mvc_Micro_handle ()
   from /usr/lib/php5/20121212/phalcon.so
No symbol table info available.
#7  0x00000000006c10fb in dtrace_execute_internal ()
No symbol table info available.
#8  0x00007ffff50795e6 in xdebug_execute_internal (
    current_execute_data=0x7ffff7fa9320, fci=0x0, return_value_used=0)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug.c:1551
        edata = <optimized out>
        fse = 0x13cb9b0
        cur_opcode = <optimized out>
        do_return = 0
        function_nr = 71
        restore_error_handler_situation = 0
---Type <return> to continue, or q <return> to quit---
        tmp_error_cb = <optimized out>
#9  0x00000000007816d5 in ?? ()
No symbol table info available.
#10 0x00000000006fb3a8 in execute_ex ()
No symbol table info available.
#11 0x00000000006c0ff9 in dtrace_execute_ex ()
No symbol table info available.
#12 0x00007ffff5078b6c in xdebug_execute_ex (execute_data=0x7ffff7fa9320)
    at /build/buildd/xdebug-2.2.5/xdebug-2.2.5/xdebug.c:1437
        op_array = 0x7ffff7fdc588
        edata = <optimized out>
        dummy = 0xe5e828 <compiler_globals+392>
        fse = 0x13c67b0
        xfse = <optimized out>
        magic_cookie = <optimized out>
        do_return = 0
        function_nr = 0
        le = <optimized out>
        clear = 1
        return_val = 0x0
#13 0x00000000006d2c60 in zend_execute_scripts ()
No symbol table info available.
#14 0x0000000000672875 in php_execute_script ()
No symbol table info available.
#15 0x00000000007836ae in ?? ()
No symbol table info available.
#16 0x00000000004605d0 in main ()
No symbol table info available.

FIgure it would be best to get this info, because turning off Xdebug and installing in debug mode is not the way we want do things. Plus, others are going to have this issue as well. Getting info should at least help in researching the problem anyway.

And to think I started out wanting to write a tutorial that might get others inspired to help with writing tests or using the output of tests to write code to fill holes in the code base. And here we are, learning about a whole lot more than I set out to in the first place. Makes things fun though!

unisys12 avatar Sep 02 '14 01:09 unisys12

It looks like a xdebug bug, it assumes that call_user_func is never called from an internal function, and it's accessing the previous execution data causing the segfault: https://github.com/xdebug/xdebug/blob/9f498af7e5a930a3513f9afc569de1aab882c3d7/xdebug_stack.c#L929

ghost avatar Sep 02 '14 03:09 ghost

@phalcon Well, there ya go! :)

Will disable the xdebug extension in my environment tomorrow moring to make I do not have any other issues unrelated to this.

unisys12 avatar Sep 02 '14 03:09 unisys12