-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
LD_LIBRARY_PATH order is non-deterministic #3800
Comments
Right now Cargo doesn't maintain a DAG between these paths, so otherwise it's basically correct for it to be slightly nondeterministic (because how else would Cargo order paths?) What's the correct ordering here? |
I don't think there's a “correct” ordering. If libraries have the same name, there will be conflicts, period. In particular, crates should just not be outputting the system directory as a search path (and newer versions of openssl-sys don't, luckily). However, I think it's important that the order is deterministic to aid in debugging these issues. Possible orderings include:
|
In some sense though I'd figure that a slighlty nondeterministic order is good because it helps weed out issues like this... |
@alexcrichton, I wonder if it could be related to #3809. |
Perhaps yeah, although I wouldn't be certain |
@alexcrichton Except rare and nondeterministic issues are hell to debug. Better if certain environments trigger the bug instead, so that they can be reliably reproduced. Non-deterministic behavior in cargo has cost me more time than all other Rust bugs combined. If something makes me leave Rust, it will be the non-determinism. I'd suggest we at least sort the output. |
@nathanaeljones can you point me to the other bugs you've experience? 99.9% of the time I've found at least that nondeterminism is not the bug but rather a legitimate other bug is being exposed, and sorting just hides it. That may not be the case always though! |
Well, I ran into the static linking form of this bug very painfully, over, and over again.
Linking can be a house of cards, but with non-determinism it's trying to stack them on a spinning table. I realize that randomized failure may cause a wider number of environments to experience a bug at least once, but it also diminishes the probability that anyone can make a useful or reproducible bug report. I'm an independent solo developer who bet the house (literally) on Rust. I abandoned Microsoft dev tools (primarily) for their propensity towards non-deterministic failure. Rust seemed to offer the best guarantees for building reliable and predictable systems. I realize Cargo is not Rust, but I did expect that determinism would be considered a virtue. I realize that purging HashMaps from Cargo won't solve all the non-determinism, but I think it's good to consider the cost/benefit for things that risk inducing I-can't-do-my-job rage. Sometimes list.sort() is cheap after all. |
100x this. Non-determinism in the build chain is also an impediment to reproducible builds. |
As I push the edges of Cargo's less tested feature set, I often run into things that don't do what I'd expect. When they're deterministic, I know what I changed before it broke, I change it back - and I'm back to work. With non-determinism, I've gone as long as 9 days between the crucial change and the error appearing. My project is < 12kloc, and I'm doing everything I can to decrease compile times and avoid problematic areas. But I have no idea how I'm going to keep things working at 20 or 30kloc and perhaps 2x as many dependencies... |
I realize that this can be painful and I'm sorry you've had to go through this sort of build pain. To be clear a major goal of Cargo is reproducible and deterministic builds. I'm definitely not a proponent that we should just randomize everything. Most of the breakage so far seems to have been accidental non-determinism simply inherited through use of a @nathanaeljones it's interesting you bring up #3659 though. The initial commit to fix that (22096de) was actually incorrect. The final result actually addressed the underlying bug with using a With that in mind, is there a way to fix this bug? If there's no correct choice, how does Cargo select a choice? |
TL;DR, I think we should sort. @alexcrichton I feel like you and the others on this thread are talking past each other a bit.
|
@alexcrichton I see #3659 differently; the input is deterministic and has explicit order, but that order is lost due to storage in a HashMap. Given the source information is deterministic, it makes sense that one could hash it in natural order... but the HashMap causes random permutation, and likely caused the assumption behind the bug to be incorrect. Using order-preserving maps would have solved both issues. When randomness is hidden behind abstraction (as it was here in fundamental data structures), it tends to cause errors. |
@nathanaeljones BTW, would you be up for a video call with me and @alexcrichton at some point soon? I know that you've been dealing with non-determinism and other Cargo-related issues, as well as some pkg-config issues, and I think some high-bandwidth discussion might be helpful for making progress together. If that sounds good, drop me a line at aturon@mozilla.com |
Sort native library paths for deterministic builds Fixes #3800 by using a `BTreeSet`, which guarantees a deterministic iteration order. Since the order was previously arbitrary, a sorted order is just as good. The list is so small, that any performance difference between `BTreeSet` and `HashSet` is negligible.
Running this program with
PQ_LIB_DIR=/test cargo run
will result in either of the following outputs:This can lead to very confusing intermittent problems, especially with crates such as openssl-sys 0.7 which include the system lib directory.
The text was updated successfully, but these errors were encountered: