-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
New panic with env_logger and with #[windows_subsystem = "windows"] #88576
Comments
Likely cause is that when the "windows" subsystem is used, the std handles will all be null (i.e. they don't exist). From the backtrace it looks like something is expecting them to always be a valid handle value. EDIT: Oh wait, that's probably termcolor not checking for null before making a |
It expects a |
winapi-util does this: https://github.com/BurntSushi/winapi-util/blob/master/src/win.rs#L139 It assumes it can call |
The crash goes away if I change the env_logger = { version = "0.9", default-features = false, features = ["humantime", "regex"] } As such, one option here would be to say that Another option would be to say that |
cc the io_safety tracking issue |
Maybe it would be worthwhile to get BurntSushi's thoughts, since this affects Personally I would be ok with "just update your dependencies" as a solution, but maintaining backward compatibility might be more important for the libraries team... |
In any case this would cause other problems. Windows processes can be freely attached or detached from consoles no mater which |
In that case, it seems like the best option is to change |
Hm, |
Good catch; |
As discussed in rust-lang#88576, raw handle values in Windows can be null, such as in `windows_subsystem` mode, or when consoles are detached from a process. So, don't use `NonNull` to hold them, don't assert that they're not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI use case.
This is now implemented in #88798. |
@sunfishcode Would it make sense to just use |
@joshtriplett User code like this means that |
Ideally |
I agree, returning a handle to @joshtriplett Is there anything else I should investigate here? |
This makes me sad, but this makes sense. I don't think this needs further investigation. I posted a bit of code review on the PR, but otherwise this should probably go ahead. |
FYI, this bug made it to stable 1.56.0 today. |
Is the resolution for this to pin on Rust 1.55 until 1.57 is released? |
Yes, I expect that's the best thing we can do for now. The real fix is #88798. Once that's reviewed and landed, I'll ask about backporting it. |
Is there a fix landed yet (e.g., does nightly work)? If so, we can discuss backporting it -- I've temporarily added a 1.57 milestone (to make sure we take a look before that ships), as this was previously not tracked as a regression and so did not receive the appropriate attention for the 1.56 release where it regressed originally. |
why? this is a regression that shipped in 1.56! |
My bad. I looked at the milestone and was worried it might've been mislabeled (by me) but I don't think that's actually the case. |
I'll review the fix today. |
Thank you Josh, it's much appreciated. The GUI target for the most popular OS being broken is a pretty severe thing imho (since so many crates use env_logger automatically), so definitely don't want that staying broken too long. I guess most Rustaceans don't use Rust on Windows, because I'm surprised no one has been yelling bloody murder about this bug. I only found it after trying to compile a release build of my employer's project. |
@Subsentient Many Rustaceans use Windows, and many build non-CLI apps, but I have the impression many do not combine that with things that get stdout handles. |
This is the kind of issue that you are likely to hit accidentally as mentioned in #88576 (comment). Not specifically because you are building a Windows GUI application that also writes to stdout. |
Correct, it seems a sizable percentage of crates initialize env_logger on their own, which means that if you're building a non-trivial application, odds are high that you'll hit this bug. Or maybe you just get lucky? But two of my non-trivial projects with no crates in common are hitting this bug. In other words, this bug is more urgent than it may have first appeared to maintainers. |
…handles, r=joshtriplett Fix assertion failures in `OwnedHandle` with `windows_subsystem`. As discussed in rust-lang#88576, raw handle values in Windows can be null, such as in `windows_subsystem` mode, or when consoles are detached from a process. So, don't use `NonNull` to hold them, don't assert that they're not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI use case. r? `@joshtriplett`
#88798 has now landed, the latest Rust nightly (936238a) now includes it, and using that, I can compile and run the testcase successfully. |
Work around rust-lang/rust#88576 until the fix lands in stable.
I'm following the steps documented here for backporting changes to beta. |
As discussed in rust-lang#88576, raw handle values in Windows can be null, such as in `windows_subsystem` mode, or when consoles are detached from a process. So, don't use `NonNull` to hold them, don't assert that they're not null, and remove `OwnedHandle`'s `repr(transparent)`. Introduce a new `HandleOrNull` type, similar to `HandleOrInvalid`, to cover the FFI use case. (cherry picked from commit 3b97481)
Backported in #90938. |
Rust 1.57, which was just released, contains the fix for this. I've confirmed that the testcase reported here is fixed. |
…ld-system-reviewers,nalexander Differential Revision: https://phabricator.services.mozilla.com/D133015
…ld-system-reviewers,nalexander Differential Revision: https://phabricator.services.mozilla.com/D133015
This was initially reported in rust-cli/env_logger#214, but I'm adding it here for additional eyes and because this issue doesn't occur on stable Rust. I could be wrong but this looks like this is caused by #87329 ... cc @sunfishcode ?
I spent an hour trying to reduce a minimal test case for this error I started experiencing with my app. So far I have produced the following:
When running this on any nightly compiler since
nightly-2021-08-21
, I get an error like this:Adjusting the profile to
panic = "abort"
causes an even more ominous error:Here's a stack trace from windbg:
If I'm reading this correctly, the panic is from this assertion:
rust/library/std/src/os/windows/io/handle.rs
Line 183 in 50171c3
The text was updated successfully, but these errors were encountered: