Skip to content

Add SIGTERM handler for a graceful shutdown #39

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 1 commit into from
Oct 17, 2019

Conversation

hug-dev
Copy link
Member

@hug-dev hug-dev commented Oct 14, 2019

Changes the wait_for_connection function in the Listen trait to be
non-blocking. That allows checking in the main loop if the SIGTERM
signal has been raised.

Testing:

[hugdev@localhost parsec]$ ./target/debug/parsec &
[1] 11951
[hugdev@localhost parsec]$ kill 11951
[hugdev@localhost parsec]$ SIGTERM signal received.
Shutting down PARSEC, waiting for all threads to finish.

[1]+  Done                    ./target/debug/parsec

@hug-dev hug-dev added the enhancement New feature or request label Oct 14, 2019
@hug-dev
Copy link
Member Author

hug-dev commented Oct 14, 2019

Implement point 2 of #35

Copy link
Collaborator

@paulhowardarm paulhowardarm left a comment

Choose a reason for hiding this comment

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

Looks good.

src/bin/main.rs Outdated
}

//TODO: this value should come from the configuration.
thread::sleep(Duration::from_millis(10));
Copy link
Member

Choose a reason for hiding this comment

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

You can probably put this in an else branch above to "simulate" a timeout on the socket, so that you only sleep if there's no one waiting for a connection.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea!

Changes the wait_for_connection function in the Listen trait to be
non-blocking. That allows checking in the main loop if the SIGTERM
signal has been raised.

Signed-off-by: Hugues de Valon <[email protected]>
@hug-dev hug-dev merged commit 7e6dbeb into parallaxsecond:master Oct 17, 2019
@hug-dev hug-dev deleted the graceful-shutdown branch October 17, 2019 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants