Skip to content

Add client and Netty ByteBuf leak detection infrastructure for Cosmos SDK#47203

Closed
Copilot wants to merge 1 commit intousers/fabianm/TestImprovementsfrom
copilot/sub-pr-47200-another-one
Closed

Add client and Netty ByteBuf leak detection infrastructure for Cosmos SDK#47203
Copilot wants to merge 1 commit intousers/fabianm/TestImprovementsfrom
copilot/sub-pr-47200-another-one

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Description

Implements leak detection infrastructure to identify unclosed CosmosClient instances and unreleased Netty ByteBuf allocations during testing. Disabled by default, enabled via COSMOS.CLIENT_LEAK_DETECTION_ENABLED system property.

Changes

Core Infrastructure:

  • Added StackTraceUtil for capturing call stacks at client creation points
  • Implemented client tracking in RxDocumentClientImpl via addToActiveClients()/removeFromActiveClients() lifecycle hooks
  • Added getActiveClientsSnapshot() to expose leaked client diagnostics

Netty Integration:

  • Custom ResourceLeakDetectorFactory with PARANOID level detection and sampling interval of 1
  • Overridden reportTracedLeak(), reportUntracedLeak(), reportInstancesLeak() to collect leak records
  • Scoped leak detection disable via createDisableLeakDetectionScope() AutoCloseable

Test Integration:

  • TestNG lifecycle hooks (@BeforeClass/@AfterClass) capture client and ByteBuf leak deltas per test class
  • resetIdentifiedLeaks() provides leak records with forced GC to trigger Netty finalizers

Implementation spans azure-cosmos-tests and azure-cosmos-encryption test modules.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 7, 2025
Copilot AI changed the title [WIP] Add tests to implement leak detection Add client and Netty ByteBuf leak detection infrastructure for Cosmos SDK Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants