Skip to content

Commit 83cdedf

Browse files
authored
fix startup panic by raising shutdown channel buffer to 1 (#24)
1 parent 3fbd9dd commit 83cdedf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/server.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub async fn run(listener: TcpListener, shutdown: impl Future) -> crate::Result<
132132
// A broadcast channel is used to signal shutdown to each of the active
133133
// connections. When the provided `shutdown` future completes
134134
let (notify_shutdown, _) = broadcast::channel(1);
135-
let (shutdown_complete_tx, shutdown_complete_rx) = mpsc::channel(0);
135+
let (shutdown_complete_tx, shutdown_complete_rx) = mpsc::channel(1);
136136

137137
// Initialize the listener state
138138
let mut server = Listener {
@@ -181,10 +181,12 @@ pub async fn run(listener: TcpListener, shutdown: impl Future) -> crate::Result<
181181
}
182182
}
183183

184-
// Extract the `shutdown_complete` receiver. By not mentioning
185-
// `shutdown_receiver` here, it is dropped. This is important, as the
184+
// Extract the `shutdown_complete` receiver and transmitter
185+
// ` explicitly drop shutdown_transmitter`. This is important, as the
186186
// `.await` below would otherwise never complete.
187-
let Listener { mut shutdown_complete_rx, .. } = server;
187+
let Listener { mut shutdown_complete_rx, shutdown_complete_tx, .. } = server;
188+
189+
drop(shutdown_complete_tx);
188190

189191
// Wait for all active connections to finish processing. As the `Sender`
190192
// handle held by the listener has been dropped above, the only remaining

0 commit comments

Comments
 (0)