Skip to content

Fix: ignore invalid object counts to prevent infinite full-scan loops - #156

Merged
sni merged 2 commits into
sni:masterfrom
dgilm:hotfix/ignore-invalid-object-counts
Sep 24, 2025
Merged

Fix: ignore invalid object counts to prevent infinite full-scan loops#156
sni merged 2 commits into
sni:masterfrom
dgilm:hotfix/ignore-invalid-object-counts

Conversation

@dgilm

@dgilm dgilm commented Sep 23, 2025

Copy link
Copy Markdown
Contributor

In lmd v2.2.0, change detection (hasChanged(ctx)) relies on countFromServer() to compare remote object counts against the local cache.

If countFromServer() fails (e.g. backend does not support Stats: queries or an error occurs), it returns -1. This was previously treated as a real count, leading lmd to incorrectly assume the dataset had changed. The result was repeated InitAllTables(ctx) reloads and excessive CPU usage.

Changes

  • Added a guard to ignore negative count values returned from countFromServer().
  • Change detection now only triggers when the count is valid (>= 0) and different from the local cache.

Impact

  • Prevents infinite reload loops and CPU spikes when Stats: queries are unsupported or fail.
  • Minimal and safe change: no effect when valid counts are returned.

Probably fixes: #144

@sni

sni commented Sep 23, 2025

Copy link
Copy Markdown
Owner

just curios, which core does not support stats queries?

@dgilm

dgilm commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

just curios, which core does not support stats queries?

Shinken’s Livestatus implementation is notoriously spotty with Stats: across some tables

This pull request is essentially an attempt to address #144
Although we are not entirely sure this is the root cause, it is worth giving it a try (as I said before, this change has no side-effects when valid counts are returned)

@sni

sni commented Sep 24, 2025

Copy link
Copy Markdown
Owner

Sure, could you apply the patch to the latest master?
Seems like your patch is based on version 1.1.1 from 2017.

@sni
sni merged commit 5950a07 into sni:master Sep 24, 2025
2 checks passed
@sni

sni commented Sep 24, 2025

Copy link
Copy Markdown
Owner

thanks, lets see if it helps...

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.

CPU Leak detected since version 2.2.0

2 participants