Skip to content

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

Merged
Jackson Weber (JacksonWeber) merged 2 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/fix-memory-leak-pg
Mar 24, 2026
Merged

Fix memory leak: clean up listeners on repeated useAzureMonitor calls#1493
Jackson Weber (JacksonWeber) merged 2 commits into
microsoft:mainfrom
JacksonWeber:jacksonweber/fix-memory-leak-pg

Conversation

@JacksonWeber

@JacksonWeber Jackson Weber (JacksonWeber) commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

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

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>
Comment thread .github/workflows/node.js-linux-arm64.yml

@rads-1996 Radhika Gupta (rads-1996) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@JacksonWeber
Jackson Weber (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