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

Stop health check futures when upgrading the Supervisor #6717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/sup/src/manager.rs
Expand Up @@ -1065,7 +1065,17 @@ impl Manager {
ctl_shutdown_tx.send(()).ok();

match shutdown_mode {
ShutdownMode::Restarting => {}
ShutdownMode::Restarting => {
outputln!("Preparing services for Supervisor restart");
for (_ident, svc) in self.state
.services
.write()
.expect("Services lock is poisoned!")
.iter_mut()
{
svc.detach();
}
}
ShutdownMode::Normal | ShutdownMode::Departed => {
outputln!("Gracefully departing from butterfly network.");
self.butterfly.set_departed_mlw();
Expand Down
27 changes: 25 additions & 2 deletions components/sup/src/manager/service.rs
Expand Up @@ -344,6 +344,7 @@ impl Service {
/// Consumes the handle to that future in the process.
fn stop_health_checks(&mut self) {
if let Some(h) = self.health_check_handle.take() {
debug!("Stopping health checks for {}", self.pkg.ident);
h.terminate();
}
}
Expand All @@ -358,6 +359,29 @@ impl Service {
self.start_health_checks(executor);
}

/// Called when the Supervisor reattaches itself to an already
/// running service. Use this to re-initiate any associated
/// processes, futures, etc.
///
/// This should generally be the opposite of `Service::detach`.
fn reattach(&mut self, executor: &TaskExecutor) {
outputln!("Reattaching to {}", self.service_group);
self.initialized = true;
self.restart_health_checks(executor);
}

/// Called when stopping the Supervisor for an update. Should
/// *not* stop the service process itself, but should stop any
/// associated processes, futures, etc., that would otherwise
/// prevent the Supervisor from shutting itself down.
///
/// Currently, this means stopping any associated long-running
/// futures.
///
/// See also `Service::reattach`, as these methods should
/// generally be mirror images of each other.
pub fn detach(&mut self) { self.stop_health_checks(); }

/// Return a future that will shut down a service, performing any
/// necessary cleanup, and run its post-stop hook, if any.
pub fn stop(&mut self,
Expand Down Expand Up @@ -924,8 +948,7 @@ impl Service {
fn execute_hooks(&mut self, launcher: &LauncherCli, executor: &TaskExecutor) {
if !self.initialized {
if self.check_process() {
outputln!("Reattached to {}", self.service_group);
self.initialized = true;
self.reattach(executor);
christophermaier marked this conversation as resolved.
Show resolved Hide resolved
return;
}
self.initialize();
Expand Down
6 changes: 5 additions & 1 deletion test/end-to-end/hup-does-not-abandon-services.exp
Expand Up @@ -72,6 +72,10 @@ expect {
}
}

# Let the control gateway come up. :/
# Alternatively, use `nc -wv localhost 9632`
sleep 1

# Load up Redis on that Supervisor
spawn hab svc load core/redis
expect {
Expand Down Expand Up @@ -115,7 +119,7 @@ expect {
}
}
expect {
"Reattached to redis.default" {
"Reattaching to redis.default" {
log "Supervisor reattached"
}
timeout {
Expand Down