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
std: Slightly more robust env var handling #29305
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
It would probably be nicer to include either the error code or the offending key, rather than just a static message. |
Also, do we want to treat invalid key as missing? Should we also treat File::open("\0") as file not found? |
Hm that's true about treating an invalid key, I'll switch it back to being a panic. |
d3ee040
to
639f98b
Compare
As discovered in rust-lang#29298, `env::set_var("", "")` will panic, but it turns out that it *also* deadlocks on Unix systems. This happens because if a panic happens while holding the environment lock, we then go try to read RUST_BACKTRACE, grabbing the environment lock, causing a deadlock. Specifically, the changes made here are: * The environment lock is pushed into `std::sys` instead of `std::env`. This also only puts it in the Unix implementation, not Windows where the functions are already threadsafe. * The `std::sys` implementation now returns `io::Result` so panics are explicitly at the `std::env` level. The panic messages have also been improved in these situations.
639f98b
to
4b43e07
Compare
ping r? @brson |
@bors r+ |
📌 Commit 4b43e07 has been approved by |
As discovered in #29298, `env::set_var("", "")` will panic, but it turns out that it *also* deadlocks on Unix systems. This happens because if a panic happens while holding the environment lock, we then go try to read RUST_BACKTRACE, grabbing the environment lock, causing a deadlock. Specifically, the changes made here are: * The environment lock is pushed into `std::sys` instead of `std::env`. This also only puts it in the Unix implementation, not Windows where the functions are already threadsafe. * The `std::sys` implementation now returns `io::Result` so panics are explicitly at the `std::env` level.
As discovered in #29298,
env::set_var("", "")
will panic, but it turns outthat it also deadlocks on Unix systems. This happens because if a panic
happens while holding the environment lock, we then go try to read
RUST_BACKTRACE, grabbing the environment lock, causing a deadlock.
Specifically, the changes made here are:
std::sys
instead ofstd::env
. Thisalso only puts it in the Unix implementation, not Windows where the functions
are already threadsafe.
std::sys
implementation now returnsio::Result
so panics areexplicitly at the
std::env
level.