Skip to content

Commit d76b9f8

Browse files
committed
FuturesUnordered: fix partial iteration
The IntoIter impl advances the head pointer every iteration, but this breaks the linked list invariant that the head's prev should be null. If the iteration is not done to completion, on subsequent drop, FuturesUnordered::unlink relies on this broken invariant and ends up panicking. The fix is to maintain the `head->prev == null` invariant while iterating.
1 parent 9ec7707 commit d76b9f8

File tree

1 file changed

+4
-0
lines changed
  • futures-util/src/stream/futures_unordered

1 file changed

+4
-0
lines changed

futures-util/src/stream/futures_unordered/iter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::task::Task;
22
use super::FuturesUnordered;
33
use core::marker::PhantomData;
44
use core::pin::Pin;
5+
use core::ptr;
56
use core::sync::atomic::Ordering::Relaxed;
67

78
/// Mutable iterator over all futures in the unordered set.
@@ -58,6 +59,9 @@ impl<Fut: Unpin> Iterator for IntoIter<Fut> {
5859
// valid `next_all` checks can be skipped.
5960
let next = (**task).next_all.load(Relaxed);
6061
*task = next;
62+
if !task.is_null() {
63+
*(**task).prev_all.get() = ptr::null_mut();
64+
}
6165
self.len -= 1;
6266
Some(future)
6367
}

0 commit comments

Comments
 (0)