Skip to content

Commit

Permalink
Fix memory leak with sidecar trace sender
Browse files Browse the repository at this point in the history
And set LSAN_OPTIONS=fast_unwind_on_malloc=0 for more complete traces

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi committed Oct 4, 2024
1 parent bb96a53 commit 0d94b95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Q := @
, := ,
PROJECT_ROOT := ${PWD}
TRACER_SOURCE_DIR := $(PROJECT_ROOT)/src/
ASAN ?= $(shell ldd $(shell which php) 2>/dev/null | grep -q libasan && echo 1)
Expand Down Expand Up @@ -156,7 +157,7 @@ run_tests: $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-tests.php
DD_TRACE_GIT_METADATA_ENABLED=0 $(RUN_TESTS_CMD) $(TESTS)

test_c: $(SO_FILE) $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-tests.php
$(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))
$(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))

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

# Just test it does not crash, i.e. the exit code
test_internal_api_randomized: $(SO_FILE)
$(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 ==============)
$(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 ==============)

composer.lock: composer.json
$(call run_composer_with_retry,,)
Expand Down
4 changes: 2 additions & 2 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ PHP_FUNCTION(dd_trace_internal_fn) {
} else
#endif
if (ddtrace_sidecar) {
ddog_sidecar_flush_traces(&ddtrace_sidecar);
ddtrace_ffi_try("Failed synchronously flushing traces", ddog_sidecar_flush_traces(&ddtrace_sidecar));
}
RETVAL_TRUE;
#ifndef _WIN32
Expand Down Expand Up @@ -2577,7 +2577,7 @@ PHP_FUNCTION(dd_trace_synchronous_flush) {
} else
#endif
if (ddtrace_sidecar) {
ddog_sidecar_flush_traces(&ddtrace_sidecar);
ddtrace_ffi_try("Failed synchronously flushing traces", ddog_sidecar_flush_traces(&ddtrace_sidecar));
}
RETURN_NULL();
}
Expand Down

0 comments on commit 0d94b95

Please sign in to comment.