From 83cdedf34f88a224be71f8f6e425eedfddde3e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Sun, 5 Apr 2020 21:17:51 +0100 Subject: [PATCH] fix startup panic by raising shutdown channel buffer to 1 (#24) --- src/server.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/server.rs b/src/server.rs index e06a95a..8dbdc4b 100644 --- a/src/server.rs +++ b/src/server.rs @@ -132,7 +132,7 @@ pub async fn run(listener: TcpListener, shutdown: impl Future) -> crate::Result< // A broadcast channel is used to signal shutdown to each of the active // connections. When the provided `shutdown` future completes let (notify_shutdown, _) = broadcast::channel(1); - let (shutdown_complete_tx, shutdown_complete_rx) = mpsc::channel(0); + let (shutdown_complete_tx, shutdown_complete_rx) = mpsc::channel(1); // Initialize the listener state let mut server = Listener { @@ -181,10 +181,12 @@ pub async fn run(listener: TcpListener, shutdown: impl Future) -> crate::Result< } } - // Extract the `shutdown_complete` receiver. By not mentioning - // `shutdown_receiver` here, it is dropped. This is important, as the + // Extract the `shutdown_complete` receiver and transmitter + // ` explicitly drop shutdown_transmitter`. This is important, as the // `.await` below would otherwise never complete. - let Listener { mut shutdown_complete_rx, .. } = server; + let Listener { mut shutdown_complete_rx, shutdown_complete_tx, .. } = server; + + drop(shutdown_complete_tx); // Wait for all active connections to finish processing. As the `Sender` // handle held by the listener has been dropped above, the only remaining