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

Segmentation Fault in Phalcon 1.3.x #2516

Closed
klaussilveira opened this issue Jun 10, 2014 · 9 comments
Closed

Segmentation Fault in Phalcon 1.3.x #2516

klaussilveira opened this issue Jun 10, 2014 · 9 comments

Comments

@klaussilveira
Copy link
Contributor

I have an intermittent problem with Phalcon 1.3.x, running on several different stack combinations:

  • PHP 5.5.9, PHP 5.4.4
  • Nginx 1.4.6, Nginx 1.6.0

Nginx gives me the following:

[error] 5467#0: *38 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: bla.com, request: "GET /my-route HTTP/1.1", upstream: "fastcgi://unix:/var/run/api.sock:", host: "bla.com"

I have attached GDB to the PHP-FPM pool, and got this backtrace on the segfault:

#0  0x000000000070c479 in gc_zval_possible_root ()
#1  0x00000000006fadb8 in zend_hash_destroy ()
#2  0x00000000006ec22b in _zval_dtor_func ()
#3  0x00000000006dd300 in _zval_ptr_dtor ()
#4  0x00000000006f9775 in ?? ()
#5  0x00000000006faf78 in zend_hash_graceful_reverse_destroy ()
#6  0x00000000006dd9e6 in shutdown_executor ()
#7  0x00000000006ed1e2 in zend_deactivate ()
#8  0x000000000068d62d in php_request_shutdown ()
#9  0x0000000000463524 in main ()

I'm really sorry, but i can't provide any further details on this. I have tried to isolate the problem, but the thing is: it's happening on almost all routes, in a 1/10 proportion. Sometimes it segfaults, sometimes it does not. That trace back there, i got it after making the very same request 3 times. The 4th time i got the segfault.

I have analyzed the process with Valgrind and got something like 20k+ uninitialized variable warnings and many leak errors. I have compiled both PHP and Phalcon in debug mode so i could make my life easier in stepping the code.

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

@klaussilveira
Copy link
Contributor Author

I also have noticed that your test suite is pretty unstable. Take this, for example: https://travis-ci.org/phalcon/cphalcon/builds/26888915

It's a simple CHANGELOG fix, but it broke the whole thing on random PHP versions. This happens on other commits as well. Most are mysterious segfaults.

@dreamsxin
Copy link
Contributor

Could you tell me this request execution which operations? Or use which Phalcon components, you can rule out under which components are out of the question.

@pgasiorowski
Copy link
Contributor

@klaussilveira do you, by any chance, use Memcache/Libmemcached session adapter and/or Session bags in your app?

I've managed to isolate current segfaults a little, which led me to SessionTest and SessionBagTests.
Tracking this down further I left:

  • SessionTest::testSessionMemcache(), testSessionLibmemcached()
  • SessionBagTest::testGetSet()

It's interesting that running these two separately does not segfault, but with one after another I can repro this.

Here's full gdb:
https://travis-ci.org/WooDzu/cphalcon/jobs/28132592

My guess is that there is something wrong with how sessions are destroyed.

@bezl
Copy link

bezl commented Jul 4, 2014

Hello! I have the same problem with Phalcon - stable 1.3.2. I tried with several combinations on my Mac:

  • Nginx 1.4.6, Nginx 1.6.0 + php-fpm (php 5.4.30, php 5.3.28)
  • Nginx 1.6.0 + Apache 2.2.26 + php5_module (php 5.3.28)
  • php54 web server + php 5.4.30

but got crashes with 502 Bad Gateway.

After Phalcon\Http\Response::send() I check Phalcon\Http\Response::isSent() and successfully log all Phalcon\Http\Response::getContent() with headers.

But sometimes with .core, sometimes without it I have the following diagnostic reports:

https://github.com/bezl/api/blob/master/php-fpm_2014-07-04-134157_BezlMac.crash
https://github.com/bezl/api/blob/master/httpd_2014-07-04-163237_BezlMac.crash

I don't use sessions in any case.

@bezl
Copy link

bezl commented Jul 9, 2014

Hello again! The problem doesn't appear on Phalcon v.1.2.6.
I checked with current stable 1.3.2 on FreeBSD 9.2 and it was also failed. So I decided to downgrade Phalcon to v1.2.6 and got stable positive result.

@cdekok
Copy link

cdekok commented Jul 16, 2014

We where having problems too with segfault when upgrading from 1.2.4 to 1.3.2 :(

@swen100
Copy link

swen100 commented Jul 17, 2014

At me too; downgraded from 1.3.2 to 1.2.6 and the error went away. But now i dont have the full list of methods which are available at 1.3.x :-(

@bezl
Copy link

bezl commented Jul 17, 2014

The only method I removed was Phalcon\Http\Response::getHeaders()->toArray() but for me it was not critical. Also I believe that all new methods from 1.3.x can be written with 1.2.6 and logic from 1.3.x source code. But I don't know how to tell guys from Phalcon about current issue with stable segfault... I can't freeze Phalcon version for my project development with v1.2.6.

@dreamsxin
Copy link
Contributor

@phalcon
I use the machine for installation test, the system environment:
Machine A:
PHP 5.4.30
Phalcon1.3.2

Machine B:
PHP 5.3.10 upgrade to PHP 5.4.30
Phalcon1.3.2

Machine C:
PHP 5.3.10 upgrade to PHP 5.4.30
Phalcon1.3.2

Machine D:
PHP 5.4.30
Phalcon1.3.2

The machine B、C is happen error, A、D is fine. The upgrade is cover installation.

The following code will appear this error
Code example 1:

$session->set('data', 1);
$apps = Robots::findFirst(array(
             'conditions' => 'id = :id:'
             'bind' => array('id' => $session->get('data'))
 ));

Code example 2:

$json = json_encode(array(1, 2, 3));
$arr = json_decode($json);
$builder->from('Robots')->inWhere('id', $arr)->getQuery()->executue();

My guess is that PHP array operation when happen this problem.

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

6 participants