fix: crashes in ZTS build because of overloaded functions #958
+27
−78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes dunglas/frankenphp#563, closes api-platform/api-platform#2670, closes dunglas/symfony-docker#534, closes https://bugs.xdebug.org/view.php?id=2216, and likely many other random bugs and crashes with ZTS builds.
Rationale:
The function table is (as expected) a different copy for each thread, but each copy points to the same underlying
zend_function
s, and as we modify them in concurrent threads,, we have a thread safety issue.In
xdebug_base_overloaded_functions_setup
, if a thread changesorig->internal_function.handler
, then a concurrent thread readsorig->internal_function.handler
and stores its value inXG_BASE(orig_error_reporting_func)
,XG_BASE(orig_error_reporting_func)
points to the Xdebug version, instead of to the PHP internal function, and whenXG_BASE(orig_error_reporting_func)
is called... we get infinite recursion.This patch moves function overloading in
MINIT
, as it looks expected: https://www.phpinternalsbook.com/php7/extensions_design/hooks.html#overwriting-an-internal-functionThis also allows to simplify the code.
I tested it on Linux, and it fixes the crashes as expected.