GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — libnetdata: reserve the log rate-limit window under its lock by stelfrag · Pull Request #24249 · netdata/netdata

Conversation

@stelfrag

@stelfrag stelfrag commented Oct 11, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

netdata_logger_with_limit() checked the rate-limit window under the limiter's spinlock, but wrote last_logged and reset count only after logging, outside the lock. Threads sharing one limiter (nd_log_limit_static_global_var) could all pass the check before any of them moved the window, so a flood emitted duplicates; an attempt counted while another thread was logging was also erased by the late reset.

The window is now reserved (and the count reset) before unlocking; the log call still runs outside the lock. Side effect: the next window starts when a message is admitted rather than when its logging finishes.

Tested on beast with a test-only harness (16 threads logging through one shared limiter at the same instant, 300 rounds, 3 repeats):

  • master: 544 / 610 / 779 lines instead of 300, duplicates in 112-229 of 300 rounds
  • fix: exactly 300 lines every time, no duplicates
  • -W unittest passes

Note: draft #24006 splits this function into nd_log_limit_admit() / nd_log_limit_emitted(); on rebase, the window reservation belongs inside nd_log_limit_admit() (under the lock) and nd_log_limit_emitted() is no longer needed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the consistency of rate-limited logging when multiple events are handled concurrently, helping keep log limits accurate.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stelfrag
libnetdata: reserve the log rate-limit window under its lock
b9065bc
netdata_logger_with_limit() checked the window under the limiter's lock
but wrote last_logged and reset count only after logging, outside it.
Threads sharing a limiter could all pass the check before any of them
moved the window, so floods emitted duplicates, and an attempt counted
during logging was erased by the late reset.

Move the window and reset the count before unlocking; logging still
happens outside the lock.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fa468f49-35d6-4969-ae3b-05733f55d668

📥 Commits

Reviewing files that changed from the base of the PR and between 1af7795 and b9065bc.


📒 Files selected for processing (1)
  • src/libnetdata/log/nd_log.c

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



📝 Walkthrough

Walkthrough

netdata_logger_with_limit now updates the logging window timestamp and resets the count while holding the error-limit spinlock, before it logs.

Changes

Error-limit logging

Layer / File(s) Summary
Reserve logging window under lock
src/libnetdata/log/nd_log.c
The function updates erl->last_logged and resets erl->count before releasing the spinlock. It removes the updates that previously occurred after logging.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: vkalintiris


Merge Risk: ⚪ Minimal · up to b9065

Concurrent callers sharing a limiter can no longer all pass the same window check, while log emission remains outside the lock. The change is ready to merge after normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to b9065

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/libnetdata/log/nd_log.c: netdata_logger_with_limit now reserves the logging window and resets the count before releasing the spinlock; previously, those updates occurred after the logging call and outside the lock.
  • observed — Modified behavior in src/libnetdata/log/nd_log.c: The post-logging updates to erl->last_logged and erl->count were removed because they now occur under the lock before logging.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: reserving the log rate-limit window while holding its lock.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cubic-dev-ai[bot]
cubic-dev-ai Bot reviewed Oct 11, 2026
View reviewed changes

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Re-trigger cubic

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sonarqubecloud

sonarqubecloud Bot commented Oct 11, 2026

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stelfrag
stelfrag marked this pull request as ready for review October 12, 2026 08:55
@stelfrag
stelfrag requested review from thiagoftsm and vkalintiris as code owners October 12, 2026 08:55
@stelfrag stelfrag mentioned this pull request Oct 12, 2026
libnetdata: check log flood protection before formatting #24280
Merged
thiagoftsm
thiagoftsm approved these changes Oct 13, 2026
View reviewed changes

@thiagoftsm thiagoftsm left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

PR is running as expected. LGTM!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stelfrag
stelfrag merged commit 24a0fb9 into netdata:master Oct 14, 2026
205 of 206 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@stelfrag
stelfrag deleted the fix-nd-log-limit-race branch October 14, 2026 05:20
@stelfrag stelfrag mentioned this pull request Oct 26, 2026
Patch release 2.12.3 #24442
Merged
Ferroin pushed a commit that referenced this pull request Nov 4, 2026
@stelfrag @Ferroin
libnetdata: reserve the log rate-limit window under its lock (#24249)
f8e0f60
netdata_logger_with_limit() checked the window under the limiter's lock
but wrote last_logged and reset count only after logging, outside it.
Threads sharing a limiter could all pass the check before any of them
moved the window, so floods emitted duplicates, and an attempt counted
during logging was erased by the late reset.

Move the window and reset the count before unlocking; logging still
happens outside the lock.

(cherry picked from commit 24a0fb9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cubic-dev-ai cubic-dev-ai[bot] cubic-dev-ai[bot] left review comments
@thiagoftsm thiagoftsm thiagoftsm approved these changes
@vkalintiris vkalintiris Awaiting requested review from vkalintiris vkalintiris is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@stelfrag @thiagoftsm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.