Skip to content

Commit b9fa0f0

Browse files
committed
Fix memory leak with sidecar trace sender
And set LSAN_OPTIONS=fast_unwind_on_malloc=0 for more complete traces Signed-off-by: Bob Weinand <[email protected]>
1 parent bb96a53 commit b9fa0f0

4 files changed

Lines changed: 7 additions & 6 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Q := @
2+
, := ,
23
PROJECT_ROOT := ${PWD}
34
TRACER_SOURCE_DIR := $(PROJECT_ROOT)/src/
45
ASAN ?= $(shell ldd $(shell which php) 2>/dev/null | grep -q libasan && echo 1)
@@ -156,7 +157,7 @@ run_tests: $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-tests.php
156157
DD_TRACE_GIT_METADATA_ENABLED=0 $(RUN_TESTS_CMD) $(TESTS)
157158

158159
test_c: $(SO_FILE) $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-tests.php
159-
$(if $(ASAN), USE_ZEND_ALLOC=0 USE_TRACKED_ALLOC=1) DD_TRACE_GIT_METADATA_ENABLED=0 $(RUN_TESTS_CMD) -d extension=$(SO_FILE) $(BUILD_DIR)/$(subst $(BUILD_DIR_NAME)/,,$(TESTS))
160+
$(if $(ASAN), USE_ZEND_ALLOC=0 USE_TRACKED_ALLOC=1 LSAN_OPTIONS=fast_unwind_on_malloc=0$${LSAN_OPTIONS:+$(,)$${LSAN_OPTIONS}}) DD_TRACE_GIT_METADATA_ENABLED=0 $(RUN_TESTS_CMD) -d extension=$(SO_FILE) $(BUILD_DIR)/$(subst $(BUILD_DIR_NAME)/,,$(TESTS))
160161

161162
test_c_coverage: dist_clean
162163
DD_TRACE_DOCKER_DEBUG=1 EXTRA_CFLAGS="-fprofile-arcs -ftest-coverage" $(MAKE) test_c || exit 0
@@ -1405,7 +1406,7 @@ test_api_unit: composer.lock global_test_run_dependencies
14051406

14061407
# Just test it does not crash, i.e. the exit code
14071408
test_internal_api_randomized: $(SO_FILE)
1408-
$(if $(ASAN), USE_ZEND_ALLOC=0 USE_TRACKED_ALLOC=1) php -n -ddatadog.trace.cli_enabled=1 -d extension=$(SO_FILE) tests/internal-api-stress-test.php 2> >(grep -A 1000 ==============)
1409+
$(if $(ASAN), DD_TRACE_DEBUG=1 USE_ZEND_ALLOC=0 USE_TRACKED_ALLOC=1 LSAN_OPTIONS=fast_unwind_on_malloc=0$${LSAN_OPTIONS:+$(,)$${LSAN_OPTIONS}}) php -n -ddatadog.trace.cli_enabled=1 -d extension=$(SO_FILE) tests/internal-api-stress-test.php 2> >(grep -A 1000 ==============)
14091410

14101411
composer.lock: composer.json
14111412
$(call run_composer_with_retry,,)

ext/ddtrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ PHP_FUNCTION(dd_trace_internal_fn) {
24602460
} else
24612461
#endif
24622462
if (ddtrace_sidecar) {
2463-
ddog_sidecar_flush_traces(&ddtrace_sidecar);
2463+
ddtrace_ffi_try("Failed synchronously flushing traces", ddog_sidecar_flush_traces(&ddtrace_sidecar));
24642464
}
24652465
RETVAL_TRUE;
24662466
#ifndef _WIN32
@@ -2577,7 +2577,7 @@ PHP_FUNCTION(dd_trace_synchronous_flush) {
25772577
} else
25782578
#endif
25792579
if (ddtrace_sidecar) {
2580-
ddog_sidecar_flush_traces(&ddtrace_sidecar);
2580+
ddtrace_ffi_try("Failed synchronously flushing traces", ddog_sidecar_flush_traces(&ddtrace_sidecar));
25812581
}
25822582
RETURN_NULL();
25832583
}

ext/sidecar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void ddtrace_sidecar_submit_root_span_data_direct(ddtrace_root_span_data *root)
354354
changed = ddog_remote_configs_service_env_change(DDTRACE_G(remote_config_state), service_slice, env_slice, version_slice);
355355
}
356356
if (changed || !root) {
357-
ddog_sidecar_set_remote_config_data(&ddtrace_sidecar, ddtrace_sidecar_instance_id, &DDTRACE_G(sidecar_queue_id), service_slice, env_slice, version_slice, &DDTRACE_G(active_global_tags));
357+
ddtrace_ffi_try("Failed sending remote config data", ddog_sidecar_set_remote_config_data(&ddtrace_sidecar, ddtrace_sidecar_instance_id, &DDTRACE_G(sidecar_queue_id), service_slice, env_slice, version_slice, &DDTRACE_G(active_global_tags)));
358358
}
359359

360360
if (free_string) {

ext/sidecar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline zend_string *dd_CharSlice_to_zend_string(ddog_CharSlice slice) {
4646
static inline bool ddtrace_ffi_try(const char *msg, ddog_MaybeError maybe_error) {
4747
if (maybe_error.tag == DDOG_OPTION_ERROR_SOME_ERROR) {
4848
ddog_CharSlice error = ddog_Error_message(&maybe_error.some);
49-
LOG(ERROR, "%s: %.*s", msg, (int) error.len, error.ptr);
49+
LOG(WARN, "%s: %.*s", msg, (int) error.len, error.ptr);
5050
ddog_MaybeError_drop(maybe_error);
5151
return false;
5252
}

0 commit comments

Comments
 (0)