Skip to content

Commit c83c0d4

Browse files
authored
fix: drop service before sys exit (#2109)
1 parent b57ec5a commit c83c0d4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

runtime/src/rt.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ impl RuntimeEnvVars {
6868
}
6969
}
7070

71-
// uses non-standard exit codes for each scenario to help track down exit reasons
72-
pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + Send + 'static) {
71+
// Returns non-standard exit codes for each scenario to help track down exit reasons
72+
pub async fn start(
73+
loader: impl Loader + Send + 'static,
74+
runner: impl Runner + Send + 'static,
75+
) -> i32 {
7376
debug!("Parsing environment variables");
7477
let RuntimeEnvVars {
7578
shuttle,
@@ -94,6 +97,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
9497
// light hyper server
9598
let Ok(listener) = TcpListener::bind(&addr).await else {
9699
eprintln!("ERROR: Failed to bind to health check port");
100+
// TODO: figure out if exit() is appropriate to do in this future. Can we exit more smoothly?
97101
exit(201);
98102
};
99103

@@ -140,7 +144,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
140144
Ok(s) => s,
141145
Err(e) => {
142146
eprintln!("ERROR: Runtime Secret Loading phase failed: {e}");
143-
exit(101);
147+
return 101;
144148
}
145149
};
146150

@@ -153,7 +157,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
153157
Ok(r) => r,
154158
Err(e) => {
155159
eprintln!("ERROR: Runtime Loader phase failed: {e}");
156-
exit(111);
160+
return 111;
157161
}
158162
};
159163

@@ -168,7 +172,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
168172
Ok(v) => v,
169173
Err(e) => {
170174
eprintln!("ERROR: Runtime Provisioning phase failed: {e}");
171-
exit(121);
175+
return 121;
172176
}
173177
};
174178

@@ -211,13 +215,13 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
211215
shuttle_resource.r#type,
212216
bad_state
213217
);
214-
exit(132);
218+
return 132;
215219
}
216220
}
217221
}
218222
Err(e) => {
219223
eprintln!("ERROR: Runtime Provisioning phase failed: {e}");
220-
exit(131);
224+
return 131;
221225
}
222226
};
223227
}
@@ -240,7 +244,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
240244
Ok(s) => s,
241245
Err(e) => {
242246
eprintln!("ERROR: Runtime Resource Initialization phase failed: {e}");
243-
exit(151);
247+
return 151;
244248
}
245249
};
246250

@@ -263,7 +267,7 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
263267
res = service_bind => {
264268
if let Err(e) = res {
265269
tracing::error!("Service encountered an error in `bind`: {e}");
266-
exit(1);
270+
return 1;
267271
}
268272
tracing::warn!("Service terminated on its own. Shutting down the runtime...");
269273
false
@@ -323,6 +327,8 @@ pub async fn start(loader: impl Loader + Send + 'static, runner: impl Runner + S
323327
};
324328

325329
if interrupted {
326-
exit(10);
330+
return 10;
327331
}
332+
333+
0
328334
}

runtime/src/start.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ pub async fn start(
7272
guard
7373
};
7474

75-
rt::start(loader, runner).await
75+
let exit_code = rt::start(loader, runner).await;
76+
77+
// TODO: drop/shutdown logger guards
78+
79+
std::process::exit(exit_code)
7680
}

0 commit comments

Comments
 (0)