Skip to content

Conversation

@stelfrag
Copy link
Collaborator

@stelfrag stelfrag commented Dec 12, 2025

Summary
  • Add status handling to functions_evloop and update plugins for proper exit status tracking
    • Thread should not call exit directly, if the main process (e.g app_plugin) holds a mutex the auto cleanup (destructor) will cause the plugin to crash (note: it doesn't affect the main netdata process)

Summary by cubic

Propagates exit codes from functions_evloop to plugin mains. Fixes shutdown by avoiding exit() in worker threads to prevent crashes when a mutex is held.

  • Bug Fixes
    • Reader thread now stores the status (if provided) and sets plugin_should_exit using atomics; it no longer calls exit().
    • Updated plugins: apps.plugin tracks exit_status, checks the exit flag atomically, and exits with the recorded status; ebpf, freeipmi, windows-events, systemd-journal, systemd-units, and network-viewer use the new functions_evloop_init signature (status is optional) and now check plugin exit atomically to avoid race conditions.

Written for commit 11cfd84. Summary will update automatically on new commits.

@stelfrag
Copy link
Collaborator Author

@cubic-dev-ai please review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Dec 12, 2025

@cubic-dev-ai please review this PR

@stelfrag I've started the AI code review. It'll take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 6 files

@stelfrag stelfrag marked this pull request as ready for review December 12, 2025 13:51
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 6 files

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical shutdown bug by propagating exit codes from the functions_evloop reader thread to plugin mains, preventing crashes when worker threads call exit() while holding a mutex.

Key changes:

  • Added optional status parameter to functions_evloop_init() for exit code propagation
  • Replaced direct exit() calls with atomic status storage in the reader thread
  • Updated all plugins to use atomic operations when checking the exit flag

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/libnetdata/functions_evloop/functions_evloop.h Added status parameter to functions_evloop_init() signature
src/libnetdata/functions_evloop/functions_evloop.c Implemented atomic status storage; removed exit() call from reader thread
src/collectors/apps.plugin/apps_plugin.c Tracks exit status, uses atomic exit flag check, and exits with propagated status
src/collectors/windows-events.plugin/windows-events.c Updated function call with NULL status; added atomic exit flag check
src/collectors/systemd-units.plugin/plugin_systemd_units.c Updated function call with NULL status; added atomic exit flag check
src/collectors/systemd-journal.plugin/systemd-main.c Updated function call with NULL status; added atomic exit flag check
src/collectors/network-viewer.plugin/network-viewer.c Updated function call with NULL status; added atomic exit flag check
src/collectors/freeipmi.plugin/freeipmi_plugin.c Updated function call with NULL status parameter
src/collectors/ebpf.plugin/ebpf_functions.c Updated function call with NULL status parameter
src/collectors/ebpf.plugin/ebpf.h Changed ebpf_plugin_stop() to use atomic load operation
src/collectors/ebpf.plugin/ebpf.c Changed exit flag assignment to use atomic store operation

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

@stelfrag stelfrag force-pushed the adjust_functions_evloop branch from 141a464 to cf7bb03 Compare December 12, 2025 20:38
@stelfrag stelfrag force-pushed the adjust_functions_evloop branch from cf7bb03 to 11cfd84 Compare December 12, 2025 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant