Skip to content

Fix memory leak: clean up listeners on repeated useAzureMonitor calls#1493

Merged
JacksonWeber merged 2 commits intomicrosoft:mainfrom
JacksonWeber:jacksonweber/fix-memory-leak-pg
Mar 24, 2026
Merged

Fix memory leak: clean up listeners on repeated useAzureMonitor calls#1493
JacksonWeber merged 2 commits intomicrosoft:mainfrom
JacksonWeber:jacksonweber/fix-memory-leak-pg

Conversation

@JacksonWeber
Copy link
Contributor

@JacksonWeber JacksonWeber commented Mar 23, 2026

When useAzureMonitor() is called multiple times, old AutoCollectExceptions and AutoCollectLogs instances were silently overwritten without cleanup, causing process event listener accumulation and retaining old LogApi instances (and their downstream spans/connection metadata) in memory.

This adds shutdown of previous instances before re-initialization and a test verifying listeners do not accumulate.

Also fix flaky test infrastructure for testing CI.

Fixes: #1415

JacksonWeber and others added 2 commits March 23, 2026 12:55
When useAzureMonitor() is called multiple times, old AutoCollectExceptions
and AutoCollectLogs instances were silently overwritten without cleanup,
causing process event listener accumulation and retaining old LogApi
instances (and their downstream spans/connection metadata) in memory.

This adds shutdown of previous instances before re-initialization and
a test verifying listeners do not accumulate.

Fixes: microsoft#1415

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Member

@rads-1996 rads-1996 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JacksonWeber JacksonWeber merged commit f2b2a19 into microsoft:main Mar 24, 2026
12 checks passed
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.

Potential memory leak in PostgreSQL telemetry

2 participants