Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Function run time cache segmentation fault with PHP 7.1 & 7.2 #725

Closed
dktapps opened this issue Jul 24, 2017 · 1 comment
Closed

Function run time cache segmentation fault with PHP 7.1 & 7.2 #725

dktapps opened this issue Jul 24, 2017 · 1 comment
Labels

Comments

@dktapps
Copy link
Contributor

dktapps commented Jul 24, 2017

Environment

  • PHP: PHP 7.1.x and PHP 7.2.0dev
  • pthreads: 3.1.7dev
  • OS: Windows 10 x64 and Ubuntu 17.04 x64

Summary

When attempting to upgrade to PHP 7.1 (and 7.2) I've been experiencing a consistent segfault with function runtime caches being null when calling certain methods in worker tasks (in our project the segfault is occurring when this function is called).

This issue did not occur on PHP 7.0 with the same pthreads source, leading me to believe a change to php-src is to blame for this bug.

Sadly I do not know how to reproduce this bug with minimal code, I've attempted to cut it down to a reproducing test case, but have been unable to produce one.

Possible solutions
sirsnyder@fd8fac4
pmmp/ext-pmmpthread@56115b1

Both of the above commits resolve the issue in my project, however I'm a noob here.

Sorry for such a useless issue, I hope someone is better able to identify the cause of this problem than I am.

Visual Studio backtrace:

>	php7ts.dll!ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CONST_HANDLER(_zend_execute_data * execute_data) Line 28067	C
 	php7ts.dll!execute_ex(_zend_execute_data * ex) Line 59440	C
 	php7ts.dll!pthreads_execute_ex(_zend_execute_data * data) Line 150	C
 	php7ts.dll!ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(_zend_execute_data * execute_data) Line 1071	C
 	php7ts.dll!execute_ex(_zend_execute_data * ex) Line 59440	C
 	php7ts.dll!pthreads_execute_ex(_zend_execute_data * data) Line 150	C
 	php7ts.dll!ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER(_zend_execute_data * execute_data) Line 889	C
 	php7ts.dll!execute_ex(_zend_execute_data * ex) Line 59440	C
 	php7ts.dll!pthreads_execute_ex(_zend_execute_data * data) Line 150	C
 	php7ts.dll!zend_call_function(_zend_fcall_info * fci, _zend_fcall_info_cache * fci_cache) Line 818	C
 	php7ts.dll!pthreads_routine_run_function(_pthreads_object_t * object, _pthreads_object_t * connection, _zval_struct * work) Line 481	C
 	php7ts.dll!pthreads_routine(_pthreads_routine_arg_t * routine) Line 516	C
 	pthreadVC2.dll!00007ff9524369b0()	Unknown
 	[External Code]	
@dktapps
Copy link
Contributor Author

dktapps commented Aug 8, 2019

I revisited this while working on my 7.4 fork.

This call to function_add_ref() is responsible for the runtime cache destruction that triggers this bug. This 7.1 commit made the change which removes cache initialization from a hot path, on the assumption that cache is already initialized at that point.

The bug is triggered under the following approximate circumstances:

  • Worker is started without inheriting classes.
  • Class A extends AbstractClass extends Threaded is submitted. A inherits and uses some function from AbstractClass.
  • Class B extends AbstractClass extends Threaded is submitted. B inherits and uses some function from AbstractClass. This is when the fault occurs.

I still haven't been able to pin down an exact test case, but I'm closing in. I can reproduce it from within PM after removing the fix that closed this issue, but I haven't managed to cut it down to the finest parts yet.

As far as I can tell, the call to function_add_ref() here is entirely redundant in PHP 7.0+.
After removing this call, it becomes apparent that this code is redundant, because pthreads_copy_user_function() always destroys the cache of copied functions, which means there is no chance of sharing a runtime cache anyway.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants