[Internal]Cosmos Tests - Add client and Netty ByteBuf leak detection#47200
Conversation
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - kafka |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces client and Netty ByteBuf leak detection infrastructure for the Azure Cosmos Java SDK to help identify resource leaks during testing. The feature is disabled by default and can be enabled via the COSMOS.CLIENT_LEAK_DETECTION_ENABLED system property.
Key changes:
- Added a new
StackTraceUtilutility class for capturing call stacks - Implemented client leak detection tracking in
RxDocumentClientImplwith methods to register/unregister active clients - Added comprehensive Netty leak detection using a custom
ResourceLeakDetectorFactoryimplementation - Integrated leak detection checks into test base classes to detect leaks at the test class level
Reviewed Changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/StackTraceUtil.java | New utility class for capturing and formatting stack traces |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java | Added client leak detection infrastructure with static map to track active clients and their creation call stacks |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/Configs.java | Added configuration to enable/disable client leak detection via system property |
| sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/AsyncDocumentClient.java | Added try-catch in client initialization to ensure proper cleanup on init failures |
| sdk/cosmos/azure-cosmos-tests/src/test/resources/*.xml | Added CosmosNettyLeakDetectorFactory listener to all TestNG suite configuration files |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/rx/TestSuiteBase.java | Added before/after class methods to snapshot client state and report leaks |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/TestSuiteBase.java | Added before/after class methods to snapshot client state and report leaks |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosNettyLeakDetectorFactory.java | New custom Netty leak detector factory to intercept and log Netty ByteBuf leaks |
| sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosAsyncClientTest.java | Added BeforeClass import to support leak detection setup |
| sdk/cosmos/azure-cosmos-encryption/src/test/java/com/azure/cosmos/encryption/TestSuiteBase.java | Added before/after class methods to snapshot client state and report leaks for encryption tests |
| sdk/cosmos/azure-cosmos-encryption/src/test/java/com/azure/cosmos/encryption/CosmosNettyLeakDetectorFactory.java | Duplicate of the main CosmosNettyLeakDetectorFactory for the encryption module |
…mos/encryption/CosmosNettyLeakDetectorFactory.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot please review the latest iteration again |
|
@FabianMeiswinkel I've opened a new pull request, #47202, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
/azp run java - cosmos - tests |
|
/azp run java - cosmos - spark |
|
/azp run java - cosmos - kafka |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - spark |
|
Azure Pipelines successfully started running 1 pipeline(s). |
2 similar comments
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - kafka |
|
/azp run java - cosmos - spark |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Description
Implements comprehensive resource leak detection infrastructure for the Azure Cosmos Java SDK, disabled by default and enabled via
COSMOS.CLIENT_LEAK_DETECTION_ENABLEDsystem property.This PR is intentionally just adding the test infrastructure - not yet failing/blokcing tests when Netty buffer leaks or RxDocumentClientImpl leaks are detected in test code (or production code). Making any of those necessary changes in separate PRs intentionally to simplify reviews.
Changes
RxDocumentClientImplviaaddToActiveClients()/removeFromActiveClients()lifecycle hooks andgetActiveClientsSnapshot()for diagnosticsResourceLeakDetectorFactoryimplementations in test modules that intercept all three leak report types (traced, untraced, instances) with consistentisLeakDetectionDisabledflag checkingcreateDisableLeakDetectionScope()provides AutoCloseable scope to temporarily suppress leak reporting in specific test scenariosUsage
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines