Skip to content

Commit

Permalink
tmp: Split up cleanup_and_exit
Browse files Browse the repository at this point in the history
This will be squashed into the prior commit before merging. Kept it
separate for now, just to make the changes easier to review.
  • Loading branch information
sharnoff committed May 4, 2024
1 parent 8284db0 commit 483559a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions compute_tools/src/bin/compute_ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ fn main() -> Result<()> {
// PostgreSQL is now running, if startup was successful. Wait until it exits.
let wait_pg_result = wait_postgres(pg_handle, startup_context_guard)?;

cleanup_and_exit(start_pg_result, wait_pg_result)
let delay_exit = cleanup_after_postgres_exit(start_pg_result)?;

maybe_delay_exit(delay_exit);

deinit_and_exit(wait_pg_result);
}

fn init() -> Result<(String, clap::ArgMatches)> {
Expand Down Expand Up @@ -508,7 +512,7 @@ struct WaitPostgresResult {
exit_code: Option<i32>,
}

fn cleanup_and_exit(
fn cleanup_after_postgres_exit(
StartPostgresResult {
mut delay_exit,
compute,
Expand All @@ -519,8 +523,7 @@ fn cleanup_and_exit(
#[cfg(target_os = "linux")]
rt,
}: StartPostgresResult,
WaitPostgresResult { exit_code }: WaitPostgresResult,
) -> Result<()> {
) -> Result<bool> {
// Terminate the vm_monitor so it releases the file watcher on
// /sys/fs/cgroup/neon-postgres.
// Note: the vm-monitor only runs on linux because it requires cgroups.
Expand Down Expand Up @@ -562,13 +565,19 @@ fn cleanup_and_exit(
error!("error while checking for core dumps: {err:?}");
}

Ok(delay_exit)
}

fn maybe_delay_exit(delay_exit: bool) {
// If launch failed, keep serving HTTP requests for a while, so the cloud
// control plane can get the actual error.
if delay_exit {
info!("giving control plane 30s to collect the error before shutdown");
thread::sleep(Duration::from_secs(30));
}
}

fn deinit_and_exit(WaitPostgresResult { exit_code }: WaitPostgresResult) -> ! {
// Shutdown trace pipeline gracefully, so that it has a chance to send any
// pending traces before we exit. Shutting down OTEL tracing provider may
// hang for quite some time, see, for example:
Expand Down

0 comments on commit 483559a

Please sign in to comment.