We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Why assigning to a static property causes random segmentation faults?

Yesterday I started receiving strange, random 502 - Bad Gateway errors. By random I mean, when I refreshed random page several times an error sometimes occured and sometimes not, without altering any code inbetween.

I have started a horribly long debugging process. After an in-depth investigation I have found that this peace of code is causing an error:

public static function getUrlService()
{
    self::$_urlService = self::getDI()->get('url');

    return self::$_urlService;
}

It sits inside class Tag, that extends \Phalcon\Tag. I think what it is supposed to do, is to force return a service straight from DI without caching it inside _urlService property.

But whether this code is correct or not is not important. At first I tought that returning service straight from DI might cause the problem, but I went a little further a tried something like this:

public static function getUrlService()
{
    self::$_escaperService = new \stdClass();

    return self::getDI()->get('url');
}

So I basically assign a dummy object to protected static property and that seems to be the origin of the problem. If I move this assignment anywhere the problem reoccurs. The only way to solve it is to completly remove this reassignment.

As I said we do not consider if this code is correct or not, or what is the other - possibly correct way - of this assignment. I am just curious why the heck it causes a segmentation fault, as I tought that assigning to the protected static property is a valid operation?

Additional info:

Phalcon DevTools (3.1.2)

Environment:: OS: Linux user 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 PHP Version: 7.0.22-0ubuntu0.16.04.1 PHP SAPI: cli PHP Bin: /usr/bin/php7.0 PHP Extension Dir: /usr/lib/php/20151012 PHP Bin Dir: /usr/bin Loaded PHP config: /etc/php/7.0/cli/php.ini Versions:: Phalcon DevTools Version: 3.1.2 Phalcon Version: 3.1.2 AdminLTE Version: 2.3.6

Provide a back trace (gdb).

Provide a back trace (gdb).

I think we should move the discussion to this issue. You can find the trace as well as steps to reproduce.