Make BackgroundProcessor `#[must_use]` to avoid dropping immediately 2021-07-log-channel-close
authorMatt Corallo <git@bluematt.me>
Sun, 1 Aug 2021 02:42:42 +0000 (02:42 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 5 Aug 2021 20:24:21 +0000 (20:24 +0000)
It is easy for users to have a bug where they drop a
`BackgroundProcessor` immediately, causing it to start and then
immediately stop. Instead, add a `#[must_use]` tag to provide a
compiler warning for such instances.

lightning-background-processor/src/lib.rs

index 55ac14c048c412e8a9d0a7f17318d62b7569b3f6..afa3633bee69bea6b4fd2a8e2bf330a55147d143 100644 (file)
@@ -39,6 +39,7 @@ use std::ops::Deref;
 /// then there is a risk of channels force-closing on startup when the manager realizes it's
 /// outdated. However, as long as `ChannelMonitor` backups are sound, no funds besides those used
 /// for unilateral chain closure fees are at risk.
+#[must_use = "BackgroundProcessor will immediately stop on drop. It should be stored until shutdown."]
 pub struct BackgroundProcessor {
        stop_thread: Arc<AtomicBool>,
        thread_handle: Option<JoinHandle<Result<(), std::io::Error>>>,