Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Signal shutdown #1599

Merged
merged 8 commits into from Jul 20, 2019
Merged

Signal shutdown #1599

merged 8 commits into from Jul 20, 2019

Conversation

maackle
Copy link
Member

@maackle maackle commented Jul 16, 2019

PR summary

Allows conductor to shut down gracefully upon SIGINT (Ctrl+C) or SIGKILL, which also allows n3h to shut down gracefully

Necessary for try-o-rama to kill and respawn a conductor during a test

testing/benchmarking notes

There is no test written for this. It will have to be tested manually, and later, implicitly through try-o-rama tests

changelog

Please check one of the following, relating to the CHANGELOG-UNRELEASED.md

  • this is a code change that effects some consumer (e.g. zome developers) of holochain core so it is added to the CHANGELOG-UNRELEASED.md (linked above), with the format - summary of change [PR#1234](https://github.com/holochain/holochain-rust/pull/1234)
  • this is not a code change, or doesn't effect anyone outside holochain core development

@maackle maackle marked this pull request as ready for review July 16, 2019 23:43
let refs = Arc::strong_count(&CONDUCTOR);
if refs == 1 {
println!("Gracefully shutting down conductor...");
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the difference between 'graceful' shutdown and 'explicit' shutdown?

(context, I've lost the ability to fully track/understand some of the more sophisticated Rust code that's being written by y'all now)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the idea is that if the reference count for the CONDUCTOR Arc is 1 there is nobody else (no other thread) alive and running for this conductor and we don't need to explicitly call conductor.shutdown() as that is called in the Drop implementation.

But I don't completely get the difference either since we take ownership of the conductor in line 75 with mem::replace, right? So that object will be dropped at the end of the for-body's scope either way.. Isn't that right, @maackle?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this bit is a little confusing, but I figured it's better to have something than nothing. I was thinking that other threads would still have access to a conductor in the explicit shutdown case, but @lucksus is right that the conductor gets dropped either way. However, if there are other threads referencing CONDUCTOR at this point, they would wind up with a None when they expected Some(Conductor), so this warning at least explains why. I could modify the warning message a little, but I think it still mostly makes sense like this.

@Connoropolous
Copy link
Collaborator

@maackle could you toss a changelog item on here?

for _sig in termination_signals.forever() {
let mut conductor_guard = CONDUCTOR.lock().unwrap();
let conductor = std::mem::replace(&mut *conductor_guard, None);
let refs = Arc::strong_count(&CONDUCTOR);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we care about dropping the value in the conductor_guard?

Copy link
Member Author

Choose a reason for hiding this comment

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

@AshantiMutinta it will get dropped at the end of the block. What's your concern?

.stop_all_instances()
.map_err(|error| notify(format!("Error during shutdown: {}", error)));
pub fn shutdown(&mut self) -> Result<(), HolochainInstanceError> {
let _ = self.stop_all_instances()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be self.stop_all_instances()?

Copy link
Contributor

@StaticallyTypedAnxiety StaticallyTypedAnxiety 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 just some recommendations

conductor/Cargo.toml Outdated Show resolved Hide resolved
willemolding and others added 2 commits July 17, 2019 12:51
Co-Authored-By: Willem Olding <willemolding@gmail.com>
Copy link
Collaborator

@lucksus lucksus left a comment

Choose a reason for hiding this comment

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

Hm, I guess this brings us one step away from native Windows support: "It should work on any POSIX.1-2001 system, which are all the major big OSes with the notable exception of Windows."

Should we find a solution for windows as well or is this a real problem only in our app-spec CI?

let refs = Arc::strong_count(&CONDUCTOR);
if refs == 1 {
println!("Gracefully shutting down conductor...");
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the idea is that if the reference count for the CONDUCTOR Arc is 1 there is nobody else (no other thread) alive and running for this conductor and we don't need to explicitly call conductor.shutdown() as that is called in the Drop implementation.

But I don't completely get the difference either since we take ownership of the conductor in line 75 with mem::replace, right? So that object will be dropped at the end of the for-body's scope either way.. Isn't that right, @maackle?

@maackle maackle merged commit 0c7dd22 into develop Jul 20, 2019
@maackle maackle deleted the signal-shutdown branch July 20, 2019 06:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants