yoshuawuyts / futures-concurrency

Structured concurrency operations for async Rust
https://docs.rs/futures-concurrency
Apache License 2.0
413 stars 33 forks source link

fix pin violation in much of concurrentstream #187

Closed conradludgate closed 5 months ago

conradludgate commented 6 months ago

Fixes #182

I developed the crate futures-buffered a couple years ago with the intent of being a more efficient 'FuturesUnordered' type than the one in futures_util.

The core of the unsoundness in #182 are the pin-violations caused by FutureGroup slab reallocs. futures-buffered solves this by using a 'triangular array' pattern, where each subsequent realloc is actually a new slab.

Note: the unsoundness still exists in FutureGroup. futures-buffered does not return keys for entries (although that is not a bad idea) so the API is not compatible.

A quick soundness fix for FutureGroup would be to make Stream require F: Unpin, albeit this is a breaking change.

Even if you do not merge this change, I hope it serves as a nice inspiration for you :)