]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Ensure `background-processor` exits after any sleep future says to
authorMatt Corallo <git@bluematt.me>
Mon, 3 Apr 2023 20:15:04 +0000 (20:15 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 4 Apr 2023 20:59:56 +0000 (20:59 +0000)
If the user's sleep future passed to an async background processor
only returns true for exiting once and then reverts back to false,
we should exit anyway when we get a chance to. We do to this here
by always ensuring we check the exit flag even when only polling
sleep futures with no intent to (yet) exit. This is utilized in the
tests added in the coming commit(s).

lightning-background-processor/src/lib.rs

index 3dd099b495de24085d1548eee3df60a1a9e3c93a..da5f2acf86c6e2d6403ff9c113ef8c802f7e2532 100644 (file)
@@ -554,7 +554,10 @@ where
                |fut: &mut SleepFuture, _| {
                        let mut waker = dummy_waker();
                        let mut ctx = task::Context::from_waker(&mut waker);
-                       core::pin::Pin::new(fut).poll(&mut ctx).is_ready()
+                       match core::pin::Pin::new(fut).poll(&mut ctx) {
+                               task::Poll::Ready(exit) => { should_break = exit; true },
+                               task::Poll::Pending => false,
+                       }
                }, mobile_interruptable_platform)
 }