Support LSan in UT#56
Open
chenBright wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to make the unit-test suite LeakSanitizer-friendly by eliminating real leaks in tests, adding targeted leak annotations for intentional process-lifetime allocations, and introducing an LSan suppressions file for unavoidable third‑party allocations.
Changes:
- Fixes multiple unit-test leaks by tightening ownership/lifetimes (e.g., RAII with
unique_ptr, freeing buffers, releasing TLS blocks, deleting test-created objects). - Adds LSan/ASan configuration for test runs (
LSAN_OPTIONS+ASAN_OPTIONS) and introducestest/lsan_suppressions.txt. - Adds/adjusts LSan leak-annotation usage in core runtime paths (logging, thread-local caches, long-lived bthreads) and cleans up RDMA block pool teardown.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/thread_key_unittest.cpp | Keeps per-key data owned in the test to avoid LSan-reported leaks when keys are deleted. |
| test/run_tests.sh | Enables leak detection and points LSan at the suppressions file for UT runs. |
| test/object_pool_unittest.cpp | Avoids leaking new int allocations by freeing outside the timed region. |
| test/lsan_suppressions.txt | Adds suppressions for known third-party, process-lifetime allocations (gperftools). |
| test/iobuf_unittest.cpp | Releases acquired TLS block back to TLS to avoid leaking it. |
| test/CMakeLists.txt | Copies the LSan suppressions file into the test binary directory. |
| test/bthread_dispatcher_unittest.cpp | Ensures epoll thread can exit and frees/cleans up allocated test resources. |
| test/brpc_socket_unittest.cpp | Marks intentional leaks, fixes self-destruction behavior, and frees buffers on exit paths. |
| test/brpc_redis_unittest.cpp | Uses RAII for handlers/authenticator to prevent leaks in Redis UT. |
| test/brpc_redis_cluster_unittest.cpp | Makes RedisService handler ownership explicit via unique_ptr members. |
| test/brpc_protobuf_json_unittest.cpp | Replaces heap allocation with stack buffer to avoid a leak. |
| test/brpc_proto_unittest.cpp | Uses unique_ptr for dynamically allocated protobuf Message. |
| test/brpc_load_balancer_unittest.cpp | Avoids leaking SocketOptions.user and deletes a heap-allocated load balancer. |
| test/brpc_input_messenger_unittest.cpp | Frees per-thread buffers and deletes allocated client metadata. |
| test/brpc_event_dispatcher_unittest.cpp | Adds cleanup for socket user buffers and releases per-client allocations. |
| src/butil/logging.cc | Reduces retained string capacity under ASan and annotates async logging path for LSan. |
| src/butil/lazy_instance.h | Removes an include dependency while keeping leak annotations available. |
| src/butil/find_cstr.h | Annotates thread-local cache allocations to avoid false-positive leak reports. |
| src/butil/debug/leak_annotations.h | Adds explicit disable/enable helpers and updates the annotation interface. |
| src/brpc/socket_map.cpp | Adds leak-annotation usage in WatchConnections and documents intent. |
| src/brpc/server.cpp | Narrows scoped leak annotation to the intended initialization region. |
| src/brpc/rdma/block_pool.cpp | Frees mutexes and other globals during RDMA block pool destruction. |
| src/brpc/global.cpp | Disables LSan only around intentional process-lifetime constructions in GlobalUpdate. |
| .github/workflows/ci-linux.yml | Adjusts Bazel test defines used in CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a765829 to
a01946c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: