-
Notifications
You must be signed in to change notification settings - Fork 628
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
Potential unsoundness in FuturesUnordered #2786
Comments
Demonstrative example of use std::{thread, future, sync::Mutex};
use futures::{executor, stream::{FuturesUnordered, StreamExt as _}};
fn main() {
let m = Mutex::new(());
let mut f = FuturesUnordered::new();
thread::scope(|scope| {
scope.spawn(|| {
let guard = m.lock();
f.push(future::ready(guard));
});
});
dbg!(executor::block_on(f.next()));
} |
taiki-e
added a commit
that referenced
this issue
Oct 26, 2023
taiki-e
added a commit
that referenced
this issue
Oct 26, 2023
Thanks for finding this! I filed #2788 to fix this. |
taiki-e
added a commit
that referenced
this issue
Oct 26, 2023
taiki-e
added a commit
that referenced
this issue
Oct 26, 2023
taiki-e
added a commit
that referenced
this issue
Oct 26, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was browsing through the docs for FuturesUnordered when I noticed that its
Sync
bound is dependent onFut
beingSync
rather thanSend + Sync
. This theoretically allows you topush
a value that is!Send + Sync
and usepoll_next
to retrieve it from another thread. Is my understanding of this correct? Apologies for raising an issue if I’m wrong.Aside: why do
FuturesUnordered::<Fut>::iter
and the correspondingimpl<'a, Fut> IntoIterator for &'a FuturesUnordered<Fut>
requireFut: Unpin
? That requirement can be circumvented safely via e.g.Pin::new(&f).iter_pin_ref().map(Pin::get_ref)
.Aside aside: why do
iter_pin_ref
anditer_pin_mut
require it to be pinned?FuturesUnordered
implementsUnpin
unconditionally.The text was updated successfully, but these errors were encountered: