This is an automated email from the ASF dual-hosted git repository.
hello-stephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 134d19a1bc1 [test](be) Copy CDC test environment values before
mutation (#70734)
134d19a1bc1 is described below
commit 134d19a1bc1e134d83757d5db4774b4f6b714f43
Author: Mingyu Chen (Rayner) <[email protected]>
AuthorDate: Thu Nov 19 14:20:03 2026 +0800
[test](be) Copy CDC test environment values before mutation (#70734)
### Background
CDC client unit tests temporarily change DORIS_HOME, LOG_DIR and
JAVA_HOME while exercising startup errors and process ownership. The
fixture restores the original environment during cleanup and several
tests also restore it before retrying startup.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Test
Problem Summary:
The CDC fixture kept raw getenv() pointers across environment mutations.
On macOS, StartCdcClientMissingJavaHome frees the JAVA_HOME string with
unsetenv(), and TearDown() then reads the freed value through setenv(),
aborting ASAN validation. Copy the three original values into optional
strings and use those snapshots at every restore point, preserving the
distinction between unset and empty values.
### Details
- **Failure:** The ASAN integration run stopped at
StartCdcClientMissingJavaHome after six successful cases. The read is in
TearDown() and the free is in the test's unsetenv().
- **Cause:** getenv() returns borrowed storage that environment mutation
may invalidate. Saving a pointer does not preserve the original value.
The same ownership issue applies to all three saved environment
variables and intermediate restore sites.
- **Stability evidence:** After the fix, all 51 selected native ASAN
integration cases pass, including all 36 CDC cases and the original
missing-Java case. The original CI stale-generation case also passes 100
fixed repetitions. Its SIGTERM assertion and 200 ms grace period are
unchanged; this does not establish the cause of the separate Linux CI
SIGTERM receipt failure.
### Testing
- Before extracting this fix onto `master`, macOS arm64, Clang 22.1.8,
ASAN_UT with line tables: `run-be-ut.sh` selected `CdcClientMgrTest.*`
and the ORC integration cases; 51/51 passed with no skips, including all
36 CDC tests.
- On the same pre-extraction build, `GTEST_REPEAT=100
GTEST_BREAK_ON_FAILURE=1 ./run-be-ut.sh --run
--filter='CdcClientMgrTest.StaleGenerationCannotTerminateAReusedNumericPid'
-j 8`: 100/100 passed.
- The original fixture fails before this change with an ASAN
heap-use-after-free. Production CDC logic, assertions and timeouts are
unchanged.
### Notes for Reviewers
Only the CDC fixture fix is extracted here. Its source is byte-identical
to the tested candidate; the fixture baseline and production CDC source
also match current `master`. The complete binary has not been rebuilt
after extraction onto `master`. The separate ORC fix is in
apache/doris-thirdparty#437.
### Release note
None
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: local ASAN results predate
extraction onto master; the full Linux Doris BE unit suite has not run
locally
### AI Disclosure
- Tool: Codex (GPT-6)
- Generated: Fixture fix, investigation and this description
- Human review: not stated
---
be/test/runtime/cdc_client_mgr_test.cpp | 38 ++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/be/test/runtime/cdc_client_mgr_test.cpp
b/be/test/runtime/cdc_client_mgr_test.cpp
index fd35fc61c22..d7e3803668f 100644
--- a/be/test/runtime/cdc_client_mgr_test.cpp
+++ b/be/test/runtime/cdc_client_mgr_test.cpp
@@ -31,6 +31,7 @@
#include <cstdio>
#include <cstdlib>
#include <memory>
+#include <optional>
#include <thread>
#include "common/config.h"
@@ -43,6 +44,12 @@ namespace doris {
namespace {
+std::optional<std::string> snapshot_env(const char* name) {
+ // A missing variable and an empty value must remain distinct when
restoring it.
+ const char* value = std::getenv(name);
+ return value == nullptr ? std::nullopt : std::optional<std::string>(value);
+}
+
void reap_direct_child_if_present(pid_t pid) {
siginfo_t child_info {};
if (waitid(P_PID, pid, &child_info, WEXITED | WNOHANG | WNOWAIT) != 0) {
@@ -64,10 +71,11 @@ void reap_direct_child_if_present(pid_t pid) {
class CdcClientMgrTest : public testing::Test {
public:
void SetUp() override {
- // Save original environment variables
- _original_doris_home = getenv("DORIS_HOME");
- _original_log_dir = getenv("LOG_DIR");
- _original_java_home = getenv("JAVA_HOME");
+ // Missing-env tests call unsetenv("JAVA_HOME"), which can free
getenv()'s storage.
+ // Own the saved values until TearDown() and any intermediate restores
finish.
+ _original_doris_home = snapshot_env("DORIS_HOME");
+ _original_log_dir = snapshot_env("LOG_DIR");
+ _original_java_home = snapshot_env("JAVA_HOME");
// Use existing DORIS_HOME
const char* doris_home = std::getenv("DORIS_HOME");
@@ -102,19 +110,19 @@ public:
void TearDown() override {
// Restore original environment variables
if (_original_doris_home) {
- setenv("DORIS_HOME", _original_doris_home, 1);
+ setenv("DORIS_HOME", _original_doris_home->c_str(), 1);
} else {
unsetenv("DORIS_HOME");
}
if (_original_log_dir) {
- setenv("LOG_DIR", _original_log_dir, 1);
+ setenv("LOG_DIR", _original_log_dir->c_str(), 1);
} else if (_log_dir_set) {
unsetenv("LOG_DIR");
}
if (_original_java_home) {
- setenv("JAVA_HOME", _original_java_home, 1);
+ setenv("JAVA_HOME", _original_java_home->c_str(), 1);
} else {
unsetenv("JAVA_HOME");
}
@@ -132,9 +140,9 @@ protected:
std::string _log_dir;
std::string _lib_dir;
std::string _jar_path;
- const char* _original_doris_home = nullptr;
- const char* _original_log_dir = nullptr;
- const char* _original_java_home = nullptr;
+ std::optional<std::string> _original_doris_home;
+ std::optional<std::string> _original_log_dir;
+ std::optional<std::string> _original_java_home;
bool _jar_created = false;
bool _log_dir_set = false;
std::unique_ptr<ClusterInfo> _cluster_info;
@@ -444,7 +452,7 @@ TEST_F(CdcClientMgrTest, RequestCdcClientImplStartFailed) {
// Restore JAVA_HOME
if (_original_java_home) {
- setenv("JAVA_HOME", _original_java_home, 1);
+ setenv("JAVA_HOME", _original_java_home->c_str(), 1);
}
}
@@ -973,7 +981,7 @@ TEST_F(CdcClientMgrTest, StartCdcClientMissingEnv) {
// Restore JAVA_HOME
if (_original_java_home) {
- setenv("JAVA_HOME", _original_java_home, 1);
+ setenv("JAVA_HOME", _original_java_home->c_str(), 1);
}
}
@@ -1079,7 +1087,7 @@ TEST_F(CdcClientMgrTest, MultipleRequestCalls) {
// Test behavior when DORIS_HOME has trailing slash
TEST_F(CdcClientMgrTest, DorisHomeWithTrailingSlash) {
if (_original_doris_home) {
- std::string doris_home_with_slash = std::string(_original_doris_home)
+ "/";
+ std::string doris_home_with_slash = *_original_doris_home + "/";
setenv("DORIS_HOME", doris_home_with_slash.c_str(), 1);
CdcClientMgr mgr;
@@ -1090,7 +1098,7 @@ TEST_F(CdcClientMgrTest, DorisHomeWithTrailingSlash) {
EXPECT_TRUE(status.ok());
// Restore original
- setenv("DORIS_HOME", _original_doris_home, 1);
+ setenv("DORIS_HOME", _original_doris_home->c_str(), 1);
}
}
@@ -1172,7 +1180,7 @@ TEST_F(CdcClientMgrTest, StartAfterFailedStart) {
// Restore JAVA_HOME
if (_original_java_home) {
- setenv("JAVA_HOME", _original_java_home, 1);
+ setenv("JAVA_HOME", _original_java_home->c_str(), 1);
}
// Second attempt: should succeed now
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]