Skip to content

Commit c60c37e

Browse files
committed
refactor(aggregator): use new top signal for stopping HTTP server
1 parent ddce835 commit c60c37e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

mithril-aggregator/src/commands/serve_command.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl ServeCommand {
136136
println!("Press Ctrl+C to stop");
137137

138138
// Create the stop signal channel
139-
let (stop_tx, _stop_rx) = dependencies_builder
139+
let (stop_tx, stop_rx) = dependencies_builder
140140
.get_stop_signal_channel()
141141
.await
142142
.with_context(|| "Dependencies Builder can not create stop signal channel")?;
@@ -175,20 +175,20 @@ impl ServeCommand {
175175
let preload_task =
176176
tokio::spawn(async move { cardano_transactions_preloader.preload().await });
177177

178-
// sStart the HTTP server
179-
let (shutdown_tx, shutdown_rx) = oneshot::channel();
178+
// Start the HTTP server
180179
let routes = dependencies_builder
181180
.create_http_routes()
182181
.await
183182
.with_context(|| "Dependencies Builder can not create http routes")?;
183+
let mut stop_rx_clone = stop_rx.clone();
184184
join_set.spawn(async move {
185185
let (_, server) = warp::serve(routes).bind_with_graceful_shutdown(
186186
(
187187
config.server_ip.clone().parse::<IpAddr>().unwrap(),
188188
config.server_port,
189189
),
190-
async {
191-
shutdown_rx.await.ok();
190+
async move {
191+
stop_rx_clone.changed().await.ok();
192192
},
193193
);
194194
server.await;
@@ -286,9 +286,8 @@ impl ServeCommand {
286286

287287
// Stop servers
288288
join_set.shutdown().await;
289-
let _ = shutdown_tx.send(());
290289

291-
// Send the stop signal to all services
290+
// Send the stop signal
292291
let _ = stop_tx.send(());
293292

294293
if !preload_task.is_finished() {

0 commit comments

Comments
 (0)