-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Catch and handle SIGTERM: #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
89 commits
Select commit
Hold shift + click to select a range
a52c418
Add signal handler for SIGTERM and no-exit flag to install signal han…
sitaowang1998 5e99f86
Add error handling for installing signal handler
sitaowang1998 632d592
Add integration test for no exit
sitaowang1998 f7d8739
Fix test fixture not yielding values
sitaowang1998 ce95080
Reformat file
sitaowang1998 0f2753e
Fix typo
sitaowang1998 12a4145
Check stop token in fetcht task loop
sitaowang1998 eceb4d8
Add non-stop sleep when no_exit
sitaowang1998 7ebdea9
Refactor get task arguments into a separate function
sitaowang1998 010e56d
Unmark main as noreturn
sitaowang1998 0c55ded
Fix integration test typo
sitaowang1998 dea5a6f
Refactor get task arguments into a separate function
sitaowang1998 8c118ba
Rename function to avoid overload
sitaowang1998 a9f44a8
Rename args_buffer to arg_buffer
sitaowang1998 08ac7a9
Intercept SIGTERM in task executor
sitaowang1998 9d86398
Merge branch 'main' into worker_sigterm
sitaowang1998 1bf92cb
Reformat files
sitaowang1998 9be5b98
Add SIGTERM handler in scheduler to no_exit flag in scheduler
sitaowang1998 defe200
Rename global variable to avoid name shadowing
sitaowang1998 aa849ca
Fix clang tidy
sitaowang1998 115352a
Merge branch 'main' into worker_refactor
sitaowang1998 75a8544
Refactor task_loop to move setup and result handling out
sitaowang1998 b41e362
Merge branch 'worker_refactor' into worker_sigterm
sitaowang1998 7875aff
Fix task executor signal hanlder error handling
sitaowang1998 4a28913
Reinstall SIGTERM handler after user function completes
sitaowang1998 5897675
Worker resends signal to process group and update tests to start work…
sitaowang1998 3b88c28
Fix clang-tidy
sitaowang1998 cbaf131
Merge branch 'main' into worker_sigterm
sitaowang1998 f325c34
Add singleton stop token
sitaowang1998 0b7328a
Remove print in signal handler
sitaowang1998 6ebbd5d
Add task executor pid singleton and signal sending in handler
sitaowang1998 e8aaeb0
Add tests for task executor with signal handling
sitaowang1998 8195cf6
Use SIG_IGN
sitaowang1998 604d817
Add docstring
sitaowang1998 e247d1d
Fix the naming of function
sitaowang1998 180a2e2
Fix signal handler in test
sitaowang1998 f88d346
Use std::atomic_flag instead of std::sig_atomic_t for StopToken
sitaowang1998 7870a54
Add private constructor and delete copy constructor and operator for …
sitaowang1998 e77da9a
Add docstring for intergration tests
sitaowang1998 6b295a6
Delete move constructor and assignment for singleton class
sitaowang1998 9d1f889
Fix unit test that uses stop token
sitaowang1998 14ec7b2
Fix scheduler stop token
sitaowang1998 28c489b
Reformat code
sitaowang1998 ce278f0
Fix cmake signal test lib prefix
sitaowang1998 d69ad00
Remove no-exit flag and exit as if SIGTERM is not handled
sitaowang1998 f7c9fbb
Remove no-exit tests
sitaowang1998 3d03fd9
Remove unused no_exit variable in scheduler
sitaowang1998 a527b10
Use static variable for singleton pattern to avoid initialization in …
sitaowang1998 2d4cb2a
Revert "Use static variable for singleton pattern to avoid initializa…
sitaowang1998 385421c
Use sigaction instead of std::signal
sitaowang1998 2cc88fa
Rename stop_requested to is_stop_requested
sitaowang1998 3c0344f
Use static member variable for singleton pattern
sitaowang1998 fb30e65
Fix stop token in scheduler server
sitaowang1998 ed1a44f
Fix stop token in scheduler server
sitaowang1998 50be6ac
Fix clang tidy
sitaowang1998 43fa18f
Fix clang tidy
sitaowang1998 fd81e92
Fix clang tidy
sitaowang1998 b61ba60
Fix comment to ignore SIGTERM in worker.
sitaowang1998 63d70be
Fix comment for StopFlag.
sitaowang1998 ef53924
Fix comment for StopFlag in worker.
sitaowang1998 f178cf3
Rename StopToken to StopFlag
sitaowang1998 971bac4
Merge branch 'worker_sigterm' of github.com:sitaowang1998/spider into…
sitaowang1998 552b120
Add class docstring for StopFlag
sitaowang1998 26492b8
Add class docstring for ChildPid
sitaowang1998 55215c8
Delete constructor for singleton classes
sitaowang1998 bc9bbe4
Reformat code
sitaowang1998 0f115a1
Add check for worker exit code on SIGTERM and add more docstring for …
sitaowang1998 8998367
Rename StopToken to StopFlag in cmake
sitaowang1998 6551c2b
Remove unnecessary clang-tidy suppression in task executor
sitaowang1998 8745109
Remove unnecessary clang-tidy suppression in worker
sitaowang1998 3809b06
Use unique_ptr instead of shared_ptr to avoid unnecessary overhead.
sitaowang1998 8fe410e
Add job cleanup for signal integration tests.
sitaowang1998 7a11fd6
Task executor does not ignore SIGTERM by default.
sitaowang1998 daab477
Add integration test for default SIGTERM behavior.
sitaowang1998 0f0823c
Fix integration test for default SIGTERM behavior.
sitaowang1998 c81fa2c
Rename test file to solve typo and fix parent path
sitaowang1998 768f93c
Use available tcp port for scheduler instead of hard coded port
sitaowang1998 93d7f99
Use free tcp port for all integration tests and fix name shadowning
sitaowang1998 99db683
Fix scheduler port
sitaowang1998 e55de6c
Merge branch 'worker_sigterm' of github.com:sitaowang1998/spider into…
sitaowang1998 f3b9ff9
Fix job clenaup in tests
sitaowang1998 a6de071
Fix comment typo.
sitaowang1998 49c737f
Fix comment typo.
sitaowang1998 e30b97c
Fix comment typo.
sitaowang1998 dfebb43
Fix comment typo.
sitaowang1998 60ac968
Use markdown instead of html in comment.
sitaowang1998 4162329
Add signal exit in docs
sitaowang1998 f576518
Merge branch 'worker_sigterm' of github.com:sitaowang1998/spider into…
sitaowang1998 e82151c
Improve docs based on coderabbit suggestions
sitaowang1998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "StopFlag.hpp" | ||
|
|
||
| #include <atomic> | ||
|
|
||
| namespace spider::core { | ||
| auto StopFlag::request_stop() -> void { | ||
| m_stop.test_and_set(); | ||
| } | ||
|
|
||
| auto StopFlag::is_stop_requested() -> bool { | ||
| return m_stop.test(); | ||
| } | ||
|
|
||
| auto StopFlag::reset() -> void { | ||
| m_stop.clear(); | ||
| } | ||
|
|
||
| std::atomic_flag StopFlag::m_stop = ATOMIC_FLAG_INIT; | ||
| } // namespace spider::core |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #ifndef SPIDER_UTILS_STOPTOKEN_HPP | ||
| #define SPIDER_UTILS_STOPTOKEN_HPP | ||
|
|
||
| #include <atomic> | ||
|
|
||
| namespace spider::core { | ||
| /** | ||
| * @brief A singleton class that provides a stop flag for threads and signal handlers. | ||
| * | ||
| * User can call request_stop() to set the stop flag, and check if the stop flag is set. | ||
| * This class is thread-safe and signal-safe. | ||
| */ | ||
| class StopFlag { | ||
| public: | ||
| /* | ||
| * Request to token owners to stop. | ||
| */ | ||
| static auto request_stop() -> void; | ||
|
|
||
| /* | ||
| * @return A boolean indicating whether the stop was requested. | ||
| */ | ||
| [[nodiscard]] static auto is_stop_requested() -> bool; | ||
|
|
||
| /* | ||
| * Reset the stop token. | ||
| */ | ||
| static auto reset() -> void; | ||
|
|
||
| // Delete constructor | ||
| StopFlag() = delete; | ||
| // Delete copy constructor and assignment operator | ||
| StopFlag(StopFlag const&) = delete; | ||
| auto operator=(StopFlag const&) -> StopFlag& = delete; | ||
| // Delete move constructor and assignment operator | ||
| StopFlag(StopFlag&&) = delete; | ||
| auto operator=(StopFlag&&) -> StopFlag& = delete; | ||
| // Default destructor | ||
| ~StopFlag() = default; | ||
|
|
||
| private: | ||
| static std::atomic_flag m_stop; | ||
| }; | ||
| } // namespace spider::core | ||
|
|
||
| #endif |
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "ChildPid.hpp" | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| #include <csignal> | ||
|
|
||
| namespace spider::core { | ||
| auto ChildPid::get_pid() -> std::sig_atomic_t { | ||
| return m_pid; | ||
| } | ||
|
|
||
| auto ChildPid::set_pid(pid_t const pid) -> void { | ||
| m_pid = pid; | ||
| } | ||
|
|
||
| std::sig_atomic_t volatile ChildPid::m_pid = 0; | ||
| } // namespace spider::core |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.