Cphalcon: phalcon + swoole core dump

Created on 27 Apr 2019  ·  14Comments  ·  Source: phalcon/cphalcon

Core dump!!

phalcon 3.4.2 + swoole 4.2.4

$ ab -c 100 -n 10000 "http://127.0.0.1:8080/"
<?php

class HttpServer {

    public function __construct() {
        // 特别注意 Swoole 在worker_num、max_request同时为1时使用协程会卡死
        $server = new \Swoole\Http\Server("0.0.0.0", 8080);
        $server->set(array(
            'task_max_request' => swoole_cpu_num(),
            'worker_num' => swoole_cpu_num(),
            'enable_coroutine' => true,
            'max_coroutine' => 1024,
            'max_request' => 10000,
            'pid_file' => '/tmp/App.pid',
            'upload_tmp_dir' => '/tmp/',
            'document_root' => '/tmp/',
            'enable_static_handler' => true,
            'http_parse_post' => true,
            'daemonize' => false,
        ));

        $server->on('request', [$this, 'onRequest']);

        $server->start();
    }

    public function onRequest(\Swoole\Http\Request $swooleRequest, \Swoole\Http\Response $swooleResponse) {

        try {
            $app = new \Phalcon\Mvc\Micro();

            $app->get("/", function() {
                $redis = new \Swoole\Coroutine\Redis();
                $redis->connect('192.168.1.20', 6379);
                $redis->set('key', 'value');
            });

            $app->handle('/');
            $swooleResponse->end('ok' . PHP_EOL);
        } catch (\Exception $e) {
            $content = $e->getMessage() . '(' . $e->getCode() . ')' . '<br>'
                    . '<pre>' . $e->getTraceAsString() . '</pre>';
            $swooleResponse->end($content);
        }
    }

}

new HttpServer();
gdb php /tmp/core_dump/core-11-1534905748.28293
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/opt/php/bin/php...done.
[New LWP 28293]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `php server-test.php'.
Program terminated with signal 11, Segmentation fault.
#0 0x00007fe8460818cb in zephir_memory_restore_stack_common.constprop.202 ()
from /opt/php/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-13.el7.x86_64 cyrus-sasl-lib-2.1.26-23.el7.x86_64 freetype-2.4.11-15.el7.x86_64 glibc-2.17-222.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-19.el7.x86_64 libcom_err-1.42.9-12.el7_5.x86_64 libcurl-7.29.0-46.el7.x86_64 libgcc-4.8.5-28.el7_5.1.x86_64 libgcrypt-1.5.3-14.el7.x86_64 libgpg-error-1.12-3.el7.x86_64 libidn-1.28-4.el7.x86_64 libpng-1.5.13-7.el7_2.x86_64 libselinux-2.5-12.el7.x86_64 libssh2-1.4.3-10.el7_2.1.x86_64 libstdc++-4.8.5-28.el7_5.1.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 libxslt-1.1.28-5.el7.x86_64 nspr-4.19.0-1.el7_5.x86_64 nss-3.36.0-5.el7_5.x86_64 nss-softokn-freebl-3.36.0-5.el7_5.x86_64 nss-util-3.36.0-1.el7_5.x86_64 openldap-2.4.44-15.el7_5.x86_64 openssl-libs-1.0.2k-12.el7.x86_64 pcre-8.32-17.el7.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-17.el7.x86_64
(gdb) bt
#0 0x00007fe8460818cb in zephir_memory_restore_stack_common.constprop.202 ()
from /opt/php/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so
#1 0x00007fe8462be39c in zim_Phalcon_Mvc_Micro_handle ()
from /opt/php/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so
#2 0x00000000008f60fe in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER ()
at /root/soft/php-7.2.8/Zend/zend_vm_execute.h:909
#3 execute_ex (ex=0x7fe8440b9ab0) at /root/soft/php-7.2.8/Zend/zend_vm_execute.h:59765
#4 0x00007fe84591267b in swoole::Context::context_func (arg=0x2216a30)
at /root/soft/swoole-src-4.0.4/src/coroutine/context.cc:66
#5 0x00007fe8459371e1 in make_fcontext ()
at /root/soft/swoole-src-4.0.4/thirdparty/boost/asm/make_x86_64_sysv_elf_gas.S:64
#6 0x0000000000000000 in ?? ()

Details

  • Phalcon version: (php --ri phalcon) 3.4.2
  • PHP Version: (php -v) 7.2.8
  • Operating System: centos7.6
  • Installation type: Compiling from source || installing via package manager Swoole4.2.4
  • Zephir version (if any):
  • Server: Nginx | Apache | Other Swoole4.2.4
  • Other related info (Database, table schema):

Most helpful comment

Because swoole use coroutine.
This leads to the problem of zephir's global memory management, which will be changed to local variable management later.

All 14 comments

Try with 3.4.3 version, which is latest of 3.4.x

There is also same problem of version 3.4.3

/opt/php/lib/php/extensions/no-debug-non-zts-20170718/phalcon.so

You are using non-thread safe version of Phalcon. And you need to use thread safe.

The non-thread safe version should be used if you install PHP as a CGI binary, command line interface or other environment where only a single thread is used.

A thread-safe version should be used if you install PHP as an Apache module in a worker MPM (multi-processing model) or other environment where multiple PHP threads run concurrently.

I got a similar problem when I use ‘workerman’ that also is event-driven. I think this coredump maybe cause by _POST, but I don't know why ~~~~

Because swoole use coroutine.
This leads to the problem of zephir's global memory management, which will be changed to local variable management later.

你可以试下 https://github.com/phalcon/zephir/pull/1880 这个分支,看是否解决这个问题

你可以试下 phalcon/zephir#1880 这个分支,看是否解决这个问题

请教一下如何更换phalcon自带的zephir?

找了cphalcon3.4.4目录下的文件,只找到build/php7/64bits目录下有phalcon.zep.c和phalcon.zep.h,但是这两个文件是自动生成的。

问题:
1.是否只更换phalcon.zep.c和phalcon.zep.h即可
2.如何生成phalcon.zep.c和phalcon.zep.h这两个文件

感谢

@bugreporter001

# Parser

$ cd /tmp
$ git clone https://github.com/phalcon/php-zephir-parser.git
$ cd php-zephir-parser
$ git checkout development # optional
$ phpize
$ ./configure
$ make

# Zephir

$ cd /tmp
$ git clone https://github.com/phalcon/zephir.git
$ cd zephir
$ git checkout development # optional
$ composer install

# Phalcon

$ cd /tmp
$ git clone https://github.com/phalcon/cphalcon.git
$ cd cphalcon
$ git checkout 3.4.x # optional
$ php -d extension=/tmp/php-zephir-parser/modules/zephir_parser.so /tmp/zephir/zephir fullclean
$ php -d extension=/tmp/php-zephir-parser/modules/zephir_parser.so /tmp/zephir/zephir generate
$ cd build
$ php gen-build.php

@bugreporter001

```shell

Parser

$ cd /tmp
$ git clone https://github.com/phalcon/php-zephir-parser.git
$ cd php-zephir-parser
$ git checkout development # optional
$ phpize
$ ./configure
$ make

Zephir

$ cd /tmp
$ git clone https://github.com/phalcon/zephir.git
$ cd zephir
$ git checkout development # optional
$ composer install

Phalcon

$ cd /tmp
$ git clone https://github.com/phalcon/cphalcon.git
$ cd cphalcon
$ git checkout 3.4.x # optional
$ php -d extension=/tmp/php-zephir-parser/modules/zephir_parser.so /tmp/zephir/zephir fullclean
$ php -d extension=/tmp/php-zephir-parser/modules/zephir_parser.so /tmp/zephir/zephir generate
$ cd build
$ php gen-build.php

The position parameter defined by the zep file has a default value

    /**
    * Adds a route to the router without any HTTP constraint
    *
    *<code>

     * use Phalcon\Mvc\Router;
     *
     * $router->add("/about", "About::index");
     * $router->add("/about", "About::index", ["GET", "POST"]);
     * $router->add("/about", "About::index", ["GET", "POST"], Router::POSITION_FIRST);
     *</code>
     */
    public function add(string! pattern, var paths = null, var httpMethods = null, var position = Router::POSITION_LAST) -> <RouteInterface>
    {

But..

Fatal error: Declaration of AppMvcRouter::add($pattern, $paths = NULL, $httpMethods = NULL, $position = AppMvcRouter::POSITION_LAST) must be compatible with PhalconMvcRouter::add(string $pattern, $paths = NULL, $httpMethods = NULL, $position = NULL): PhalconMvcRouterRouteInterface in /opt/web/App/Mvc/Router.php on line 216

@bugreporter001 show your code here /opt/web/App/Mvc/Router.php on line 216

@bugreporter001 show your code here /opt/web/App/Mvc/Router.php on line 216

/**
 * 创建路由
 * @param string $pattern
 * @param null $paths
 * @param null $httpMethods
 * @param int|mixed $position
 * @return $this
 */
public function add($pattern, $paths = null, $httpMethods = null, $position = Router::POSITION_LAST) {

Change it to:

public function add($pattern, $paths = null, $httpMethods = null, $position = Router::POSITION_LAST): Phalcon\Mvc\Router\RouteInterface

Change it to:

public function add($pattern, $paths = null, $httpMethods = null, $position = Router::POSITION_LAST): Phalcon\Mvc\Router\RouteInterface

I mean zephir removed the default value

/**
* Adds a route to the router without any HTTP constraint
*
*<code>

 * use Phalcon\Mvc\Router;
 *
 * $router->add("/about", "About::index");
 * $router->add("/about", "About::index", ["GET", "POST"]);
 * $router->add("/about", "About::index", ["GET", "POST"], Router::POSITION_FIRST);
 *</code>
 */
public function add(string! pattern, var paths = null, var httpMethods = null, var position = Router::POSITION_LAST) -> <RouteInterface>
{

I'm closing this issue due to the lack of any reaction, but if I have made an oversight, please do get back in touch so that, I'll open it again. Thanks

Was this page helpful?
0 / 5 - 0 ratings