elastic / apm-agent-php

Apache License 2.0
252 stars 69 forks source link

Agent causing crash on Wordpress when running in Apache #1106

Open intuibase opened 9 months ago

intuibase commented 9 months ago

Describe the bug Agent is causing SIGSEGV when running with Wordpress application in Apache web server context. Crash disappears when AST processing is disabled.

To Reproduce Steps to reproduce the behavior: Install agent in wordpress:latest container and make request

Expected behavior Run stable

intuibase commented 9 months ago

backtrace

#0  0x00007f721cab2ab8 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007f721bb4fcbc in xbuf_format_converter (xbuf=0x7ffdfe9091c0, is_char=true, fmt=0x7f721c649a9b "s given", ap=0x7ffdfe909270) at /usr/src/php/main/spprintf.c:572
#2  0x00007f721bb510b2 in php_printf_to_smart_string (buf=0x7ffdfe9091c0, format=0x7f721c649a86 "must be of type %s, %s given", ap=0x7ffdfe909270) at /usr/src/php/main/spprintf.c:796
#3  0x00007f721bc13470 in zend_vspprintf (pbuf=0x7ffdfe909220, max_len=0, format=0x7f721c649a86 "must be of type %s, %s given", ap=0x7ffdfe909270) at /usr/src/php/Zend/zend.c:206
#4  0x00007f721bc1a470 in zend_argument_error_variadic (error_ce=0x56041636ead0, arg_num=1, format=0x7f721c649a86 "must be of type %s, %s given", va=0x7ffdfe909270) at /usr/src/php/Zend/zend_API.c:360
#5  0x00007f721bc1a729 in zend_argument_type_error (arg_num=1, format=0x7f721c649a86 "must be of type %s, %s given") at /usr/src/php/Zend/zend_API.c:385
#6  0x00007f721bc57a6b in zend_verify_arg_error (zf=0x7f7219c04868, arg_info=0x7f7219c624a0, arg_num=1, value=0x7f7219c12e20) at /usr/src/php/Zend/zend_execute.c:710
#7  0x00007f721bc84a64 in zend_verify_recv_arg_type (cache_slot=0x7f72160ade60, arg=0x7f7219c12e20, arg_num=1, zf=0x7f7219c04868) at /usr/src/php/Zend/zend_execute.c:1068
#8  zend_verify_recv_arg_type_helper_SPEC (op_1=0x7f7219c12e20) at /usr/src/php/Zend/zend_vm_execute.h:2470
#9  0x00007f721bd690de in ZEND_RECV_SPEC_UNUSED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:3679
#10 execute_ex (ex=0x7f7219c12dd0) at /usr/src/php/Zend/zend_vm_execute.h:55331
#11 0x00007f721bbf5338 in zend_call_function (fci=0x7ffdfe90ce90, fci_cache=0x7ffdfe90cd90) at /usr/src/php/Zend/zend_execute_API.c:895
#12 0x00007f721bbf388c in _call_user_function_impl (object=0x0, function_name=0x7ffdfe90cf10, retval_ptr=0x7ffdfe90cf20, param_count=3, params=0x7ffdfe90cf80, named_params=0x0) at /usr/src/php/Zend/zend_execute_API.c:659
#13 0x00007f7216503866 in callPhpFunction (phpFunctionName=..., argsCount=3, args=0x7f7219c12dd0, args@entry=0x7ffdfe90cf80, consumeRetVal=consumeRetVal@entry=0x7f7216503770 <consumeZvalRetVal(void*, zval const*)>, consumeRetValCtx=consumeRetValCtx@entry=0x7ffdfe910bf0)
    at /home/paplo/sources/apm-agent-php/agent/native/ext/util_for_PHP.cpp:208
#14 0x00007f7216504e7f in callPhpFunctionRetZval (phpFunctionName=..., argsCount=<optimized out>, args=args@entry=0x7ffdfe90cf80, retVal=retVal@entry=0x7ffdfe910bf0) at /home/paplo/sources/apm-agent-php/agent/native/ext/util_for_PHP.cpp:275
#15 0x00007f7216502941 in tracerPhpPartForwardCall (phpFuncName=..., execute_data=0x7f7219c12d50, retVal=0x7ffdfe910bf0, dbgCalledFrom=<optimized out>) at /home/paplo/sources/apm-agent-php/agent/native/ext/tracer_PHP_part.cpp:377
#16 0x00007f721bc6fc34 in execute_internal (execute_data=0x7f7219c12d50, return_value=0x7ffdfe910bf0) at /usr/src/php/Zend/zend_execute.c:3498
#17 0x00007f72164d517d in elasticapm::php::elastic_execute_internal (execute_data=0x7f7219c12d50, return_value=0x7ffdfe910bf0) at /home/paplo/sources/apm-agent-php/agent/native/ext/Hooking.cpp:67
#18 0x00007f721bd669f4 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /usr/src/php/Zend/zend_vm_execute.h:1757
#19 execute_ex (ex=0x7f7219c12020) at /usr/src/php/Zend/zend_vm_execute.h:55191
#20 0x00007f721bd7f453 in zend_execute (op_array=0x7f7219ded200, return_value=0x0) at /usr/src/php/Zend/zend_vm_execute.h:59523
#21 0x00007f721bc19584 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/php/Zend/zend.c:1694
#22 0x00007f721bb4aac4 in php_execute_script (primary_file=0x7ffdfe9131e0) at /usr/src/php/main/main.c:2546
#23 0x00007f721bde46be in php_handler (r=0x7f7218ca60a0) at /usr/src/php/sapi/apache2handler/sapi_apache2.c:704
#24 0x0000560414d4d9d0 in ap_run_handler ()
#25 0x0000560414d4dfc6 in ap_invoke_handler ()
#26 0x0000560414d669db in ap_process_async_request ()
#27 0x0000560414d66c1e in ap_process_request ()
#28 0x0000560414d62a94 in ?? ()
#29 0x0000560414d57730 in ap_run_process_connection ()
#30 0x00007f721c7e4bbc in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#31 0x00007f721c7e4f26 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#32 0x00007f721c7e4f71 in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#33 0x00007f721c7e567f in ?? () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#34 0x0000560414d2d820 in ap_run_mpm ()
#35 0x0000560414d25148 in main ()
intuibase commented 9 months ago
Elastic\Apm\Impl\AutoInstrument\PhpPartFacade->astInstrumentationPreHook(
arg0: unknown type 144
arg1: unknown type: 144
arg3: array(el: 2, zval: 0x7f7219c12e40 [
 0: "query",
 1: ref(array(el: 2, zval: 0x7f72160bf7a8 [
 0: obj[wpdb refc:1 obj:0x7f72160a2200 zval:0x7f72160d83c8],
 1: "remove_placeholder_escape"]))])
)
elastic_apm_ast_instrumentation_pre_hook(unreadable args)
WP_Hook->add_filter("query", ref(array(elements: 2, zval: 0x7f72160bf7a8 [
 0: obj[wpdb refc:1 obj:0x7f72160a2200 zval:0x7f72160d83c8],
 1: "remove_placeholder_escape"])), 0, 1)