Skip to content

Commit 5aba6f1

Browse files
committed
refactor(signer): update stop signal in metrics server
1 parent 1642cd6 commit 5aba6f1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

mithril-signer/src/main.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88
use std::{collections::HashMap, path::PathBuf};
99
use tokio::{
1010
signal::unix::{signal, SignalKind},
11-
sync::oneshot,
11+
sync::watch,
1212
task::JoinSet,
1313
};
1414

@@ -244,6 +244,8 @@ async fn main() -> StdResult<()> {
244244
root_logger.clone(),
245245
);
246246

247+
let (stop_tx, stop_rx) = watch::channel(());
248+
247249
let mut join_set = JoinSet::new();
248250
join_set.spawn(async move {
249251
state_machine
@@ -269,17 +271,17 @@ async fn main() -> StdResult<()> {
269271
}
270272
});
271273

272-
let (metrics_server_shutdown_tx, metrics_server_shutdown_rx) = oneshot::channel();
273274
if config.enable_metrics_server {
274275
let metrics_logger = root_logger.clone();
276+
let stop_rx_clone = stop_rx.clone();
275277
join_set.spawn(async move {
276278
MetricsServer::new(
277279
&config.metrics_server_ip,
278280
config.metrics_server_port,
279281
metrics_service,
280282
metrics_logger.clone(),
281283
)
282-
.start(metrics_server_shutdown_rx)
284+
.start(stop_rx_clone)
283285
.await
284286
.map_err(|e| anyhow!(e))
285287
.map(|_| None)
@@ -320,9 +322,9 @@ async fn main() -> StdResult<()> {
320322
None => None,
321323
};
322324

323-
metrics_server_shutdown_tx
325+
stop_tx
324326
.send(())
325-
.map_err(|e| anyhow!("Metrics server shutdown signal could not be sent: {e:?}"))?;
327+
.map_err(|e| anyhow!("Stop signal could not be sent: {e:?}"))?;
326328

327329
join_set.shutdown().await;
328330

0 commit comments

Comments
 (0)