GeezerVison is showing github.com — libnetdata: reserve the log rate-limit window under its lock by stelfrag · Pull Request #24249 · netdata/netdata
Conversation
stelfrag
commented
Oct 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
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
Bot
commented
Oct 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

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 | 4 | 1
-
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
 |
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 |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
 |
The title clearly and concisely describes the main change: reserving the log rate-limit window while holding its lock. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
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)
-
🛠️ 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
-
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.
Ferroin
pushed a commit
that referenced
this pull request
Nov 4, 2026
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)
Reviewers
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
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.
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.
|