Skip to content

Commit 9b0511e

Browse files
committed
Fix possible race condition leading to a crash upon sidecar reconnect in ZTS
Signed-off-by: Bob Weinand <[email protected]>
1 parent 72a021a commit 9b0511e

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

ext/sidecar.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,21 @@ static void dd_sidecar_on_reconnect(ddog_SidecarTransport *transport) {
144144
ddog_CharSlice env_name = dd_zend_string_to_CharSlice(DDTRACE_G(last_env_name));
145145
ddog_CharSlice version = dd_zend_string_to_CharSlice(DDTRACE_G(last_version));
146146

147+
ddog_DynamicInstrumentationConfigState dynamic_instrumentation_state;
148+
#if ZTS
149+
// With the current architecture of config it's not accessible via the TSRMLS_CACHE and thus may be actually invalid on the current thread.
150+
// This is a known issue and will be fixed with refactor of the module_globals usage of config. The current behaviour is not perfect, but has to be considered acceptable.
151+
if (zai_config_memoized_entries[DDTRACE_CONFIG_DD_DYNAMIC_INSTRUMENTATION_ENABLED].name_index >= 0) {
152+
dynamic_instrumentation_state = get_global_DD_DYNAMIC_INSTRUMENTATION_ENABLED() ? DDOG_DYNAMIC_INSTRUMENTATION_CONFIG_STATE_ENABLED : DDOG_DYNAMIC_INSTRUMENTATION_CONFIG_STATE_DISABLED;
153+
} else {
154+
dynamic_instrumentation_state = DDOG_DYNAMIC_INSTRUMENTATION_CONFIG_STATE_NOT_SET;
155+
}
156+
#else
157+
dynamic_instrumentation_state = ddtrace_dynamic_instrumentation_state();
158+
#endif
147159
ddtrace_ffi_try("Failed sending config data",
148160
ddog_sidecar_set_universal_service_tags(&transport, ddtrace_sidecar_instance_id, &DDTRACE_G(sidecar_queue_id), service_name,
149-
env_name, version, &DDTRACE_G(active_global_tags), ddtrace_dynamic_instrumentation_state()));
161+
env_name, version, &DDTRACE_G(active_global_tags), dynamic_instrumentation_state));
150162
}
151163

152164
tsrm_mutex_unlock(DDTRACE_G(sidecar_universal_service_tags_mutex));

0 commit comments

Comments
 (0)