-
Notifications
You must be signed in to change notification settings - Fork 626
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
Inconsistent ordering in select APIs #2135
Comments
From my reading of I think it would be good to add a guarantee around this to the documentation and tests that ensure it will not result in starvation when a stream is always ready. |
This is a pretty major footgun and had me and my coworker confused for several days about why we were getting inconsistent behavior in our code. I think it's important to get this situation sorted out. |
IMO I too spent a few days figuring out why my tests weren't reproducible until I read the documentation of |
@Demindiro Hey so I realized my comment wasn't clear and we were actually saying the exact opposite things. I want the behavior to be random by default, with bias being opt-in behavior. I was confused because bias was present, and in your case you were confused because the selection strategy was fair. That happened because we were using different APIs. Can you tell me more about how random selection caused a problem for you? Was starvation of the later futures desirable? |
In my case it made a specific test hard to reproduce, as the order and amount of tests run influenced the behavior of that test. Starvation is not an issue for my usecase. |
Selecting over >=2 futures has subtle fairness issues when more than one future is ready. The current offering has a few inconsistencies in docs and naming:
futures::select!
: pseudo-random, documentedfutures::select_biased!
: in-order, documentedfutures::future::{select, try_select, select_ok}
: in-order, undocumentedfutures::future::select_all
: in-order, documented that one should not rely on orderfutures::stream::select
: round-robin, documentedfutures::stream::select_all
: (based on FuturesUnordered - not sure), undocumentedGolang uses random order for
select
to prevent starvation, which is a hard-to-detect and problematic pitfall. IMO, any select API with a starvation risk should be explicitly documented as such. Even "don't rely on order" is too benign of a statement.For user-facing behavior, I'd divide the behavior of the current offering into three classes:
Initially, adding coverage of these behaviors to the existing API docstrings would be nice. Happy to create a PR upon endorsement from a maintainer.
Regarding naming, I like the precedent set by the macros:
select!
is starvation-protected by default, andselect_biased!
has explicit ordering. Following the principle of least surprise, ideally that convention could be applied to the other APIs as well. Now, going down this road would introduce breaking changes. Maybe a maintainer can chime in?The text was updated successfully, but these errors were encountered: