Skip to content

Commit b527df8

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Spawn the server on a separate thread
This avoids blocking indefinitely if an error occurs while starting the daemon.
1 parent e759bf5 commit b527df8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/utils/daemon.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub fn start_daemon(context: &dyn Context, enable_registry_watcher: bool) -> Res
5454
// Start the web server before doing anything more expensive
5555
// Please check with an administrator before changing this (see #1172 for context).
5656
info!("Starting web server");
57-
let _server = crate::Server::start(None, false, context)?;
57+
let server = crate::Server::start(None, false, context)?;
58+
let server_thread = thread::spawn(|| drop(server));
5859

5960
let config = context.config()?;
6061

@@ -104,7 +105,11 @@ pub fn start_daemon(context: &dyn Context, enable_registry_watcher: bool) -> Res
104105
)?;
105106

106107
// Never returns; `server` blocks indefinitely when dropped
107-
Ok(())
108+
// NOTE: if a failure occurred earlier in `start_daemon`, the server will _not_ be joined -
109+
// instead it will get killed when the process exits.
110+
server_thread
111+
.join()
112+
.map_err(|_| failure::err_msg("web server panicked"))
108113
}
109114

110115
fn cron<F>(name: &'static str, interval: Duration, exec: F) -> Result<(), Error>

0 commit comments

Comments
 (0)