Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Description

Implements comprehensive resource leak detection infrastructure for the Azure Cosmos Java SDK, disabled by default and enabled via COSMOS.CLIENT_LEAK_DETECTION_ENABLED system property.

Changes

  • StackTraceUtil: New utility for capturing and formatting call stacks, used to track client creation locations
  • Client leak detection: Added tracking in RxDocumentClientImpl via addToActiveClients()/removeFromActiveClients() lifecycle hooks and getActiveClientsSnapshot() for diagnostics
  • Netty leak detection: Custom ResourceLeakDetectorFactory implementations in test modules that intercept all three leak report types (traced, untraced, instances) with consistent isLeakDetectionDisabled flag checking
  • Disable scope: createDisableLeakDetectionScope() provides AutoCloseable scope to temporarily suppress leak reporting in specific test scenarios
  • Test integration: Leak detection checks integrated into test base classes at test class granularity

Usage

// Enable via system property
System.setProperty("COSMOS.CLIENT_LEAK_DETECTION_ENABLED", "true");

// Check for active clients (indicates leaks)
Map<Integer, String> activeClients = RxDocumentClientImpl.getActiveClientsSnapshot();

// Temporarily disable leak detection
try (AutoCloseable scope = CosmosNettyLeakDetectorFactory.createDisableLeakDetectionScope()) {
    // Operations that intentionally leak or produce false positives
}

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.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add test changes to improve leak detection Add client and Netty ByteBuf leak detection infrastructure for Cosmos SDK Nov 7, 2025
@FabianMeiswinkel
Copy link
Member

No changes left

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