Never store more than one `StdWaker` per live `Future` 2024-02-future-poll-leak
authorMatt Corallo <git@bluematt.me>
Tue, 13 Feb 2024 22:43:51 +0000 (22:43 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 15 Feb 2024 21:52:06 +0000 (21:52 +0000)
commit8157c01eaba199695cec5366ea780bef23619541
tree929706e3c1e0f4eaafcb7dd56d8d2c7767203f22
parent5f404b9d0a0a160aa305b5a9421026e58c7ef609
Never store more than one `StdWaker` per live `Future`

When an `std::future::Future` is `poll()`ed, we're only supposed to
use the latest `Waker` provided. However, we currently push an
`StdWaker` onto our callback list every time `poll` is called,
waking every `Waker` but also using more and more memory until the
`Future` itself is woken.

Here we fix this by removing any `StdWaker`s stored for a given
`Future` when it is `drop`ped or prior to pushing a new `StdWaker`
onto the list when `poll`ed.

Sadly, the introduction of a `Drop` impl for `Future` means we
can't trivially destructure the struct any longer, causing a few
methods to need to take `Future`s by reference rather than
ownership and `clone` a few `Arc`s.

Fixes #2874
lightning-background-processor/src/lib.rs
lightning/src/util/wakers.rs