Skip to content

Commit 058a71f

Browse files
feat(error code when shutdown fails): set exit flag to 1 when shutdown times out (#17676)
<!-- **Your PR title must conform to the conventional commit spec!** <type>(<scope>)!: <description> * `type` = chore, enhancement, feat, fix, docs * `!` = OPTIONAL: signals a breaking change * `scope` = Optional when `type` is "chore" or "docs", available scopes https://github.com/vectordotdev/vector/blob/master/.github/semantic.yml#L20 * `description` = short description of the change Examples: * enhancement(file source): Add `sort` option to sort discovered files * feat(new source): Initial `statsd` source * fix(file source): Fix a bug discovering new files * chore(external docs): Clarify `batch_size` option --> Issue: [Exit non-zero when Vector fails to gracefully shutdown](#13731) We use [std::process::ExitCode](https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html) to provide the default platform-specific success and failure codes.
1 parent 19c4d4f commit 058a71f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/app.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#![allow(missing_docs)]
2-
use std::{collections::HashMap, num::NonZeroUsize, path::PathBuf, time::Duration};
2+
use std::{
3+
collections::HashMap, num::NonZeroUsize, path::PathBuf, process::ExitCode as Exit,
4+
time::Duration,
5+
};
36

47
use exitcode::ExitCode;
58
use futures::StreamExt;
@@ -145,10 +148,10 @@ impl ApplicationConfig {
145148
}
146149

147150
impl Application {
148-
pub fn run() {
151+
pub fn run() -> Exit {
149152
let (runtime, app) = Self::prepare_start().unwrap_or_else(|code| std::process::exit(code));
150153

151-
runtime.block_on(app.run());
154+
runtime.block_on(app.run())
152155
}
153156

154157
pub fn prepare_start() -> Result<(Runtime, StartedApplication), ExitCode> {
@@ -242,7 +245,7 @@ pub struct StartedApplication {
242245
}
243246

244247
impl StartedApplication {
245-
pub async fn run(self) {
248+
pub async fn run(self) -> Exit {
246249
self.main().await.shutdown().await
247250
}
248251

@@ -317,7 +320,7 @@ pub struct FinishedApplication {
317320
}
318321

319322
impl FinishedApplication {
320-
pub async fn shutdown(self) {
323+
pub async fn shutdown(self) -> Exit {
321324
let FinishedApplication {
322325
signal,
323326
mut signal_rx,
@@ -335,18 +338,20 @@ impl FinishedApplication {
335338
SignalTo::Shutdown => {
336339
emit!(VectorStopped);
337340
tokio::select! {
338-
_ = topology_controller.stop() => (), // Graceful shutdown finished
341+
_ = topology_controller.stop() => Exit::SUCCESS, // Graceful shutdown finished
339342
_ = signal_rx.recv() => {
340343
// It is highly unlikely that this event will exit from topology.
341344
emit!(VectorQuit);
342345
// Dropping the shutdown future will immediately shut the server down
346+
Exit::FAILURE
343347
}
344348
}
345349
}
346350
SignalTo::Quit => {
347351
// It is highly unlikely that this event will exit from topology.
348352
emit!(VectorQuit);
349353
drop(topology_controller);
354+
Exit::FAILURE
350355
}
351356
_ => unreachable!(),
352357
}

src/main.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
extern crate vector;
44
use vector::app::Application;
55

6+
use std::process::ExitCode;
7+
68
#[cfg(unix)]
7-
fn main() {
9+
fn main() -> ExitCode {
810
#[cfg(feature = "allocation-tracing")]
911
{
1012
use crate::vector::internal_telemetry::allocations::{
@@ -35,14 +37,14 @@ fn main() {
3537
}
3638
}
3739

38-
Application::run();
40+
Application::run()
3941
}
4042

4143
#[cfg(windows)]
42-
pub fn main() {
44+
pub fn main() -> ExitCode {
4345
// We need to be able to run vector in User Interactive mode. We first try
4446
// to run vector as a service. If we fail, we consider that we are in
4547
// interactive mode and then fallback to console mode. See
4648
// https://docs.microsoft.com/en-us/dotnet/api/system.environment.userinteractive?redirectedfrom=MSDN&view=netcore-3.1#System_Environment_UserInteractive
47-
vector::vector_windows::run().unwrap_or_else(|_| Application::run());
49+
vector::vector_windows::run().unwrap_or_else(|_| Application::run())
4850
}

0 commit comments

Comments
 (0)