Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed resetting state for forks #1125

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading