Skip to content

Commit e7904ce

Browse files
committed
Bias Selector to first poll the sleeper future
Previously, `lightning-background-processor`'s `Selector` would poll all other futures *before* finally polling the sleeper and returning the `exit` flag if it's ready. This could lead to scenarios where we infinitely keep processing background events and never respect the `exit` flag, as long as any of other futures keep being ready. Here, we instead bias the `Selector` to always *first* poll the sleeper future, and hence have us act on the `exit` flag immediately if is set.
1 parent de384ff commit e7904ce

File tree

1 file changed

+8
-6
lines changed
  • lightning-background-processor/src

1 file changed

+8
-6
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,14 @@ pub(crate) mod futures_util {
509509
fn poll(
510510
mut self: Pin<&mut Self>, ctx: &mut core::task::Context<'_>,
511511
) -> Poll<SelectorOutput> {
512+
// Bias the selector so it first polls the sleeper future, allowing to exit immediately
513+
// if the flag is set.
514+
match Pin::new(&mut self.e).poll(ctx) {
515+
Poll::Ready(res) => {
516+
return Poll::Ready(SelectorOutput::E(res));
517+
},
518+
Poll::Pending => {},
519+
}
512520
match Pin::new(&mut self.a).poll(ctx) {
513521
Poll::Ready(()) => {
514522
return Poll::Ready(SelectorOutput::A);
@@ -533,12 +541,6 @@ pub(crate) mod futures_util {
533541
},
534542
Poll::Pending => {},
535543
}
536-
match Pin::new(&mut self.e).poll(ctx) {
537-
Poll::Ready(res) => {
538-
return Poll::Ready(SelectorOutput::E(res));
539-
},
540-
Poll::Pending => {},
541-
}
542544
Poll::Pending
543545
}
544546
}

0 commit comments

Comments
 (0)