Skip to content

KAFKA-20398: Fix memory leak by removing StreamsThreadMetricsDelegatingReporter from metrics registry on thread shutdown#21973

Merged
bbejeck merged 1 commit intoapache:trunkfrom
sstremler:KAFKA-20398-remove-metrics-reporter-from-registry-on-shutdown
Apr 7, 2026
Merged

KAFKA-20398: Fix memory leak by removing StreamsThreadMetricsDelegatingReporter from metrics registry on thread shutdown#21973
bbejeck merged 1 commit intoapache:trunkfrom
sstremler:KAFKA-20398-remove-metrics-reporter-from-registry-on-shutdown

Conversation

@sstremler
Copy link
Copy Markdown
Contributor

@sstremler sstremler commented Apr 6, 2026

When a stream thread in Kafka Streams crashes,
StreamsUncaughtExceptionHandler can be configured to replace the
crashed thread with a new one. Each time a new stream thread is created,
it adds a new StreamsThreadMetricsDelegatingReporter to it. However,
when the old thread shuts down, its reporter is never removed from the
registry implying "unbounded" memory growth.

This bug was introduced via #17021

This PR ensures that the existing
StreamsThreadMetricsDelegatingReporter is removed when a thread is
shutting down.

Reviewers: Matthias J. Sax matthias@confluent.io, Bill Bejeck
bbejeck@apache.org

…ngReporter from metrics registry on thread shutdown

Signed-off-by: Szabolcs Stremler <stremler.sz@gmail.com>
@github-actions github-actions bot added triage PRs from the community streams small Small PRs labels Apr 6, 2026
@mjsax mjsax added ci-approved and removed triage PRs from the community labels Apr 7, 2026
Copy link
Copy Markdown
Member

@mjsax mjsax left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix. LGTM.

Copy link
Copy Markdown
Member

@bbejeck bbejeck left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, LGTM

@bbejeck bbejeck merged commit 71c0882 into apache:trunk Apr 7, 2026
28 checks passed
@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented Apr 7, 2026

Merged #21971 into trunk

bbejeck pushed a commit that referenced this pull request Apr 7, 2026
…ngReporter from metrics registry on thread shutdown (#21973)

When a stream thread in Kafka Streams crashes,
`StreamsUncaughtExceptionHandler` can be configured to replace the
crashed thread with a new one. Each time a new stream thread is created,
it adds a new `StreamsThreadMetricsDelegatingReporter` to it. However,
when the old thread shuts down, its reporter is never removed from the
registry implying "unbounded" memory growth.

This bug was introduced via #17021

This PR ensures that the existing
`StreamsThreadMetricsDelegatingReporter` is removed when a thread is
shutting down.

Reviewers: Matthias J. Sax <matthias@confluent.io>, Bill Bejeck
 <bbejeck@apache.org>

Signed-off-by: Szabolcs Stremler <stremler.sz@gmail.com>
@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented Apr 7, 2026

cherry-picked to 4.3

@bbejeck
Copy link
Copy Markdown
Member

bbejeck commented Apr 7, 2026

@sstremler I tried cherry-picking to 4.2 but there are some conflcts, can you do a separate PR for 4.2?

@sstremler
Copy link
Copy Markdown
Contributor Author

@sstremler I tried cherry-picking to 4.2 but there are some conflcts, can you do a separate PR for 4.2?

@bbejeck Sure: #21989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants