Skip to content
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

Correctly handle SIGINT/SIGTERM for graceful exit #181

Merged
merged 7 commits into from
Jul 19, 2022

Conversation

psrok1
Copy link
Member

@psrok1 psrok1 commented Jul 18, 2022

Signal handlers should not be set inside the constructor of Karton class, because in case of incorrect invocation:

KartonClass().main()

KartonClass instance is set twice and GracefulKiller doesn't correctly fallback to default handler. I replaced it with context manager and raising own exception (HardShutdownInterrupt) in case of second try.

In previous implementation, second try handler was spawned only when second SIGINT arrived. Should we do the same for SIGTERM? After short research I think hard shutdown should be implemented only for SIGINT.

@psrok1 psrok1 marked this pull request as ready for review July 18, 2022 14:07
@psrok1 psrok1 marked this pull request as draft July 18, 2022 14:08
@psrok1 psrok1 marked this pull request as ready for review July 19, 2022 10:05
@psrok1 psrok1 requested a review from nazywam July 19, 2022 10:52
self._shutdown = True

@property
def shutdown(self):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a chance that some users try to shut down the service on their own by setting this to True?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't seen that pattern, but we can expose it in more controlled way in a future.

@psrok1 psrok1 merged commit 6df87ea into master Jul 19, 2022
@psrok1 psrok1 deleted the fix/correct-shutdown-handling branch July 19, 2022 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants