[BUG]: Segfault coming from Phalcon\Mvc\Model\Query::_getQualified #15555
Labels
5.0
The issues we want to solve in the 5.0 release
bug
A bug report
external dependency
This issue depends on external issue to be resolved.
Describe the bug
Periodically, we have a strange bug on our production, when during the execution of a simple SELECT query through the query builder there is segfault. This is somehow related to
Query::_getQualified
and Zephir.To Reproduce
It will be problematic to provide the code of the Models since they are too complex, but for example, the Query Builder is:
Segfault occurs during the
execute
method.Full trace:
I was able to track the last executed methods from the trace, which led to line 211 (which is
#4
in the trace):cphalcon/phalcon/Mvc/Model/Query.zep
Lines 206 to 215 in ae581a3
Apparently there is something wrong with an array
this->sqlColumnAliases
. Since I did not find any obvious problems with this method and my code I added some debugging in this method (dirty hack, don't judge me) :After that, by logs, I realized that almost always this method is executed successfully, and mostly these variables are as follows:
So, the
this->sqlColumnAliases
property is always an empty array. But in the case of segfault, this array contains a single nested empty array (actually this may not be true, since this is not a valid php code, but a C/extension, so there may be invalid pointer or something else):Currently I tested the extension from the Packagecloud, Phalcon 4.1.2. I suggested that this error may be related to Zephir. Therefore, I tried to compile manually and see how the same code will work (I have not changed anything in my PHP project).
As I understood, there was some kind of bug with the Zephir 0.12.21 (used by default with Phalcon 4.1.2), this bug was still in Zephir 0.13.2, but was fixed in 0.13.3. This led me to commits zephir-lang/zephir@0ca7737 and zephir-lang/zephir@0ca7737 from PR zephir-lang/zephir#2222, not sure if they are related.
So, please confirm my guess:
There is a bug in Phalcon 4.1.2 due to Zephir 0.12.21 (current default), and this bug was fixed by Zephir 0.13.3?
Expected behavior
Segfault does not occur.
If my guesses are right, then need to either backport the changes from Zephir 0.13.3 to 0.12.x, and then use Zephir 0.12.x in the current stable Phalcon 4.1.x. Or switch to Zephir 0.13.x in Phalcon 4.1.x.
I think that this is an important bug to fix it in the current/latest stable version of Phalcon 4.1.x, and not to postpone it up to 5.0 which is still in alpha and is unknown when it will be released.
Details
The text was updated successfully, but these errors were encountered: