Skip to content

fix(diskspace): initialize mountpoint state before slow worker - #22298

Merged
stelfrag merged 2 commits into
netdata:masterfrom
stelfrag:fix_diskspace_plugin
Apr 28, 2026
Merged

fix(diskspace): initialize mountpoint state before slow worker#22298
stelfrag merged 2 commits into
netdata:masterfrom
stelfrag:fix_diskspace_plugin

Conversation

@stelfrag

@stelfrag stelfrag commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator
Summary

Move diskspace mountpoint dictionary and pattern initialization out of the collection fast path and run it before starting the slow worker thread.

The slow worker can run cleanup independently, so publishing the shared mountpoint dictionary lazily allowed it to observe partially initialized state and crash while reading mountpoint metadata.


Summary by cubic

Initialize the diskspace mountpoint dictionary, exclusion patterns, and slow_mountinfo_mutex before publishing the function endpoint and starting the slow worker to prevent races on partially initialized state. Moves initialization out of the collection fast path.

  • Bug Fixes
    • Initialize dict_mountpoints, exclusion patterns, and slow_mountinfo_mutex in diskspace_main() via diskspace_mountpoints_init() before rrd_function_add_inline() and before spawning the slow worker.
    • Free exclusion patterns during plugin cleanup and make mountpoint_delete_cb static.

Written for commit 31a0f37. Summary will update on new commits. Review in cubic

Move diskspace mountpoint dictionary and pattern initialization out of the collection fast path and run it before starting the slow worker thread.

The slow worker can run cleanup independently, so publishing the shared mountpoint dictionary lazily allowed it to observe partially initialized state and crash while reading mountpoint metadata.
@github-actions github-actions Bot added area/collectors Everything related to data collection collectors/diskspace labels Apr 28, 2026
@stelfrag
stelfrag marked this pull request as ready for review April 28, 2026 07:20
Copilot AI review requested due to automatic review settings April 28, 2026 07:20
@stelfrag
stelfrag requested a review from thiagoftsm as a code owner April 28, 2026 07:20
@stelfrag
stelfrag marked this pull request as draft April 28, 2026 07:20

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant Main as diskspace_main (Main Thread)
    participant Config as netdata_config
    participant State as Shared State (dict_mountpoints)
    participant Worker as slow_worker (Thread)
    participant FastPath as do_disk_space_stats (Collection)

    Note over Main, State: Initialization Phase
    
    Main->>Main: NEW: diskspace_mountpoints_init()
    Main->>Config: Get exclusion patterns/mountpoint settings
    Config-->>Main: Config values
    Main->>State: NEW: Initialize dictionary & patterns
    
    Note over Main, Worker: Thread Lifecycle
    
    Main->>Worker: spawn_pthread(slow_worker_main)
    
    loop Every update_every seconds
        Main->>FastPath: Run collection cycle
        FastPath->>State: CHANGED: Safely access initialized dictionary
        FastPath-->>Main: Update charts
        
        opt In Background
            Worker->>State: Access mountpoints for cleanup/slow ops
            Note right of Worker: Race condition avoided: State is guaranteed init
        end
    end

    Note over Main, State: Cleanup Phase
    
    Main->>State: NEW: Free exclusion patterns & destroy dictionary
Loading

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

Fixes a startup race in the diskspace collector by ensuring shared mountpoint state is initialized before the slow worker thread can observe it, avoiding crashes from partially initialized metadata.

Changes:

  • Add diskspace_mountpoints_init() to eagerly initialize dict_mountpoints and exclusion patterns.
  • Remove lazy initialization from do_disk_space_stats() fast path (keep a fallback init call).
  • Free newly-global exclusion patterns during plugin cleanup; make mountpoint delete callback static.

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

Comment thread src/collectors/diskspace.plugin/plugin_diskspace.c Outdated
@sonarqubecloud

Copy link
Copy Markdown

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

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


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

@stelfrag
stelfrag marked this pull request as ready for review April 28, 2026 07:44

@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.

Disk space is working as expected. LGTM!

@stelfrag
stelfrag merged commit f568812 into netdata:master Apr 28, 2026
162 checks passed
@stelfrag
stelfrag deleted the fix_diskspace_plugin branch April 28, 2026 13:57
@stelfrag stelfrag mentioned this pull request Jun 22, 2026
Ferroin pushed a commit that referenced this pull request Jul 15, 2026
* fix(diskspace): initialize mountpoint state before slow worker

Move diskspace mountpoint dictionary and pattern initialization out of the collection fast path and run it before starting the slow worker thread.

The slow worker can run cleanup independently, so publishing the shared mountpoint dictionary lazily allowed it to observe partially initialized state and crash while reading mountpoint metadata.

* fix(diskspace): initialize shared state before function endpoint publishing

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

Labels

area/collectors Everything related to data collection collectors/diskspace

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants