Skip to content

Commit d048e9f

Browse files
committed
Bias select toward shutdown in event stream
Ensures the shutdown signal is always checked first when both a broadcast event and shutdown are ready simultaneously.
1 parent 171bd3a commit d048e9f

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

ldk-server/src/service.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,16 @@ impl Service<Request<Incoming>> for NodeService {
369369
tokio::spawn(async move {
370370
loop {
371371
tokio::select! {
372+
biased;
373+
_ = shutdown_rx.changed() => {
374+
let _ = tx
375+
.send(Err(GrpcStatus::new(
376+
GRPC_STATUS_UNAVAILABLE,
377+
"server shutting down",
378+
)))
379+
.await;
380+
break;
381+
},
372382
result = rx.recv() => {
373383
match result {
374384
Ok(event) => {
@@ -391,15 +401,6 @@ impl Service<Request<Incoming>> for NodeService {
391401
},
392402
}
393403
},
394-
_ = shutdown_rx.changed() => {
395-
let _ = tx
396-
.send(Err(GrpcStatus::new(
397-
GRPC_STATUS_UNAVAILABLE,
398-
"server shutting down",
399-
)))
400-
.await;
401-
break;
402-
},
403404
}
404405
}
405406
});

0 commit comments

Comments
 (0)