fix(diskspace): initialize mountpoint state before slow worker - #22298
Conversation
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 initializedict_mountpointsand 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.
|
There was a problem hiding this comment.
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.
thiagoftsm
left a comment
There was a problem hiding this comment.
Disk space is working as expected. LGTM!
* 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)



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_mutexbefore publishing the function endpoint and starting the slow worker to prevent races on partially initialized state. Moves initialization out of the collection fast path.dict_mountpoints, exclusion patterns, andslow_mountinfo_mutexindiskspace_main()viadiskspace_mountpoints_init()beforerrd_function_add_inline()and before spawning the slow worker.mountpoint_delete_cbstatic.Written for commit 31a0f37. Summary will update on new commits. Review in cubic