Skip to content
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

Document possible panics for std::env::{set_var, unset_var} #29298

Merged
merged 2 commits into from Oct 27, 2015

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Oct 25, 2015

No description provided.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss
Copy link
Member

bluss commented Oct 25, 2015

The rules for both posix and windows do seem to include that the name must not contain =, still maybe it should say may panic, not guarantee panic.

In reality this API panics on any OS error from the operation. It's a bit tricky to document with certainty since the number of OSes that Rust supports will be growing.

@alexcrichton
Copy link
Member

Wow I'm surprised by this, I had no idea this could happen! In retrospect it makes sense, however.

I agree with @bluss that we probably don't want to guarantee that it panics in these situations, but rather indicate that it may panic. It may also be worth noting that if there is a nul byte on Unix (and maybe on Windows?) a panic will happen as well. The last failure mode that I know of is OOM, but I think that's fine to not document.

@alexcrichton
Copy link
Member

For anyone testing this locally as well, turns out on Unix a set_var("", "") also deadlocks, which #29305 should fix.

Previously the documentation suggested that the documentation about the
panics are guarantees.
@tbu-
Copy link
Contributor Author

tbu- commented Oct 25, 2015

@alexcrichton Changed it to "may panic". Is it better like this?

@alexcrichton
Copy link
Member

@bors: r+ fe2a47b

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 26, 2015
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.
@steveklabnik
Copy link
Member

@bors: rollup

@bors
Copy link
Contributor

bors commented Oct 27, 2015

⌛ Testing commit fe2a47b with merge cb591e5...

@bors bors merged commit fe2a47b into rust-lang:master Oct 27, 2015
bors added a commit that referenced this pull request Nov 6, 2015
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants