Skip to content

Fix sender replication counter leak on obsolete charts - #22428

Merged
stelfrag merged 2 commits into
netdata:masterfrom
stelfrag:streaming-obsolete-chart-counter-leak
May 6, 2026
Merged

Fix sender replication counter leak on obsolete charts#22428
stelfrag merged 2 commits into
netdata:masterfrom
stelfrag:streaming-obsolete-chart-counter-leak

Conversation

@stelfrag

@stelfrag stelfrag commented May 6, 2026

Copy link
Copy Markdown
Collaborator
Summary
  • Fixes a sender-side leak of rrdhost_sender_replicating_charts on streaming children that would prevent cleanup of an obsoleted chart

Summary by cubic

Fixes a sender-side leak of the replication counter for obsolete charts, unblocking obsolete-chart cleanup and preventing memory growth on streaming children. Obsolete chart definitions no longer pin rrdhost_sender_replicating_charts above zero.

  • Bug Fixes
    • On obsoletion, release any pending replication slot and flip pulse from replicating to running when the counter reaches 0.
    • In stream_sender_send_rrdset_definition: skip replication bookkeeping for obsolete charts; increment the host counter before setting IN_PROGRESS; roll back if another sender already set it; undo if the chart becomes obsolete or the host loses metadata readiness.
    • In reset: decrement only when IN_PROGRESS was set; remove force-zero; log non-zero residuals without altering the counter.
    • On disconnect: clear READY_4_METRICS before reset to block new pushes racing with the reset.

Written for commit 470a929. Summary will update on new commits.

  The sender was bumping rrdhost_sender_replicating_charts when pushing
  obsolete chart definitions, but the receiver skips replication for
  obsolete charts so the counter never decremented.  On stable streaming
  children it grew monotonically, permanently gating obsolete-chart
  cleanup and -- in RAM mode -- leaking dim mmaps until the cgroup
  OOM-killer fired

  Closes the leak end-to-end across concurrent obsoletion, sender reset,
  and disconnect: claim-before-publish ordering, post-CAS recheck with
  atomic rollback for OBSOLETE or lost readiness, precise per-chart
  accounting in sender reset (drops the racy force-zero), and an early
  READY_4_METRICS clear on disconnect.
@stelfrag
stelfrag marked this pull request as ready for review May 6, 2026 12:01
Copilot AI review requested due to automatic review settings May 6, 2026 12:01
@stelfrag
stelfrag marked this pull request as draft May 6, 2026 12:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes sender-side replication accounting so that obsolete charts don’t permanently pin rrdhost_sender_replicating_charts above zero, which would otherwise prevent cleanup of obsoleted charts on streaming children.

Changes:

  • Tightens the disconnect/reset path to only decrement the host “replicating charts” counter when a chart actually had SENDER_REPLICATION_IN_PROGRESS, and removes the previous force-zero behavior.
  • Skips entering sender replication bookkeeping for charts already marked RRDSET_FLAG_OBSOLETE, preventing counter leaks for charts the receiver won’t replicate.
  • Ensures obsolete-marking proactively releases any pending sender replication slot (clears IN_PROGRESS, decrements host counter, updates pulse status on 0 boundary).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/streaming/stream-sender.c Makes per-chart reset decrement logic precise (keyed on IN_PROGRESS) and avoids force-zeroing the host counter; clears sender readiness earlier on disconnect.
src/streaming/protocol/command-chart-definition.c Avoids replication bookkeeping for obsolete charts and adds claim/rollback logic to keep host counter balanced under races.
src/database/rrdset.c When a chart becomes obsolete, releases any pending sender replication slot immediately to avoid pinning the host replication counter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stelfrag
stelfrag marked this pull request as ready for review May 6, 2026 12:12

@thiagoftsm thiagoftsm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Streaming is working as expected locally. LGTM!

@thiagoftsm thiagoftsm self-assigned this May 6, 2026
@sonarqubecloud

sonarqubecloud Bot commented May 6, 2026

Copy link
Copy Markdown

@stelfrag
stelfrag merged commit 177a3b6 into netdata:master May 6, 2026
158 checks passed
@stelfrag
stelfrag deleted the streaming-obsolete-chart-counter-leak branch May 6, 2026 21:02
@stelfrag stelfrag mentioned this pull request Jun 22, 2026
Ferroin pushed a commit that referenced this pull request Jul 15, 2026
streaming: stop sender replication counter leak on obsolete charts

  The sender was bumping rrdhost_sender_replicating_charts when pushing
  obsolete chart definitions, but the receiver skips replication for
  obsolete charts so the counter never decremented.  On stable streaming
  children it grew monotonically, permanently gating obsolete-chart
  cleanup and -- in RAM mode -- leaking dim mmaps until the cgroup
  OOM-killer fired

  Closes the leak end-to-end across concurrent obsoletion, sender reset,
  and disconnect: claim-before-publish ordering, post-CAS recheck with
  atomic rollback for OBSOLETE or lost readiness, precise per-chart
  accounting in sender reset (drops the racy force-zero), and an early
  READY_4_METRICS clear on disconnect.

(cherry picked from commit 177a3b6)
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