Skip to content

Commit

Permalink
Fixed resseting state for forks (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase authored Jan 24, 2024
1 parent 573e5c6 commit 1d10059
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions agent/native/ext/elastic_apm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ void unregisterElasticApmIniEntries( int type, int module_number, IniEntriesRegi

static PHP_GINIT_FUNCTION(elastic_apm)
{
// We SHOULD NOT log before resetting state if forked because logging might be using thread synchronization
// which might deadlock in forked child
if (elasticApmApiEntered( __FILE__, __LINE__, __FUNCTION__ ) != resultSuccess) {
return;
}

ELASTIC_APM_LOG_DIRECT_DEBUG( "%s: GINIT called; parent PID: %d", __FUNCTION__, (int)getParentProcessId() );
// memset(&elastic_apm_globals->globalTracer, 0, sizeof(Tracer));
elastic_apm_globals->globals = nullptr;
Expand Down Expand Up @@ -669,6 +675,12 @@ ZEND_END_ARG_INFO()
*/
PHP_FUNCTION( elastic_apm_ast_instrumentation_pre_hook )
{
// We SHOULD NOT log before resetting state if forked because logging might be using thread synchronization
// which might deadlock in forked child
if (elasticApmApiEntered( __FILE__, __LINE__, __FUNCTION__ ) != resultSuccess) {
return;
}

tracerPhpPartAstInstrumentationCallPreHook( execute_data, return_value );
}
/* }}} */
Expand All @@ -679,6 +691,11 @@ ZEND_END_ARG_INFO()
*/
PHP_FUNCTION( elastic_apm_ast_instrumentation_direct_call )
{
// We SHOULD NOT log before resetting state if forked because logging might be using thread synchronization
// which might deadlock in forked child
if (elasticApmApiEntered( __FILE__, __LINE__, __FUNCTION__ ) != resultSuccess) {
return;
}
tracerPhpPartAstInstrumentationDirectCall( execute_data );
}
/* }}} */
Expand Down

0 comments on commit 1d10059

Please sign in to comment.