Check for `background-processor` exit condition before+after sleep 2023-04-bp-exit-fast
authorMatt Corallo <git@bluematt.me>
Mon, 24 Apr 2023 03:48:42 +0000 (03:48 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 24 Apr 2023 03:49:48 +0000 (03:49 +0000)
commit05535913b3f1679298188745ab2dfc9e930b992e
tree8326872c7daf660c88e9d7941dd2a9f062e3f80d
parentbc544414247af4ceeaa53c0b3f204d7fad85d4b8
Check for `background-processor` exit condition before+after sleep

In a synchronous `BackgroundProcessor`, the exit is done by setting
an atomic flag, which is most likely to happen while we're asleep.
Thus, we previously checked for the exit condition after the sleep
(and after we persisted the `ChannelManager`, if required, though
this is no longer required and dates back to when we didn't do a
re-persist after breaking out of the main loop).

For an async `background-processor`, this is also fine, however
because of the relatively longer sleep time, if the exit flag is
set via a sleep check returning true during event processing, we
may end up delaying exit rather substantially.

In order to avoid this, we simply check for the exit condition both
before and immediately after the sleep in `background-processor`.
lightning-background-processor/src/lib.rs