fix: proper SIGINT/SIGTERM handlers for graceful resource release (fixes #121) - #223
Open
dajiaohuang wants to merge 1 commit into
Open
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
…ase (issue BabitMF#121) - Replace unreliable std::signal() with POSIX sigaction() for robust signal handling - Add support for SIGINT, SIGTERM, and SIGHUP signals - Block signal delivery during handler execution to prevent race conditions - Add double-signal protection: first signal triggers graceful shutdown, second signal forces immediate exit - Use mutex-protected global graph list for thread safety - Register graph instance in global list BEFORE signal handler installation to fix race condition - Spawn detached cleanup thread to avoid async-signal-safety issues with complex C++ operations - Properly remove graph pointer from global list on close() and destructor - Use only async-signal-safe functions (write(), _exit()) directly in signal handler - Added null-pointer safety check before graph operations - Added thread header include for std::thread support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes issue #121 by implementing proper signal handling in the BMF C++ media framework engine, ensuring graceful resource release when the process receives termination signals.
Problems with the original implementation:
Changes made:
Files changed:
Testing: Press Ctrl+C during graph execution - all nodes and resources should be properly closed. Press Ctrl+C again if stuck to force exit.