Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to subtract with overflow in FuturesUnordered's IntoIter after calling .take(n) #2573

Closed
wfraser opened this issue Feb 23, 2022 · 0 comments · Fixed by #2574
Closed
Labels
A-stream Area: futures::stream bug

Comments

@wfraser
Copy link
Contributor

wfraser commented Feb 23, 2022

Construct a FuturesUnordered, put n futures in it, call .into_iter().take(n-1) on it, and iterate the result.

Minimal example:

let _ = FuturesUnordered::from_iter(vec![ready(1), ready(2), ready(3), ready(4)])
    .into_iter()
    .take(3) // any number less than the number of futures in the collection, except zero
    .count(); // or collect into another FuturesUnordered, or whatever.

playground


Separately, while testing this, I found that if you only partially iterate that IntoIter type before dropping it, you get a different panic: future still here when dropping:

let _ = FuturesUnordered::from_iter(vec![ready(1), ready(2), ready(3), ready(4)])
    .into_iter()
    .take(3)
    .next();

playground


I also debugged this a bit and think I see what's going on. It looks like FuturesUnordered's IntoIter implementation does some brain surgery on the linked list while iterating which leaves it in a partially invalid state unless the iteration is fully completed. I'm preparing a possible fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants