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

stdin().read_u8 results in unknown error (OS Error 8 (FormatMessageW() returned error 15105)) #13304

Closed
bachm opened this issue Apr 4, 2014 · 9 comments
Labels
O-windows Operating system: Windows

Comments

@bachm
Copy link

bachm commented Apr 4, 2014

match std::io::stdin().read_u8() {
    Ok(_) => (),
    Err(e) => println!("{}",e)
}

Output: "unknown error (OS Error 8 (FormatMessageW() returned error 15100))"

Win 7
rustc 0.10
host: i686-pc-mingw32

@huonw huonw added the A-windows label Apr 4, 2014
@klutzy
Copy link
Contributor

klutzy commented Apr 4, 2014

Error 8 indicates ERROR_NOT_ENOUGH_MEMORY.
The code works for me (rustc 0.10 + win 8.1). Is the code a part of large portion which may consume lots or memeory?

@bachm
Copy link
Author

bachm commented Apr 4, 2014

No, it's just a main function containing the above code.

@alexcrichton
Copy link
Member

I suspect that this is a duplicate of #13259.

What happens if you add this right before you read from stdin?

unsafe { ::std::rt::stack::record_sp_limit(0); }

@bachm
Copy link
Author

bachm commented Apr 5, 2014

With that I get "unknown error (OS Error 8: Not enough storage is available to process this command.)"

@BrianOtto
Copy link

I am getting the same error with the following code ...

use std::io;

fn main() {
    for line in io::stdin().lines() {
        match line {
            Ok(line) => io::print(line),
            Err(err) => fail!("IO error: {}", err),
        }
    }
}

I am using Rust 0.10 on Windows 7 (i686-pc-mingw32). Please see my discussion about it on Reddit.

@alexcrichton
Copy link
Member

Apparently this is because we're using a buffered reader on windows. It looks like windows returns this error when using a 64K buffer and a 32K buffer. Decreasing it to 16K makes the kernel happy apparently (who knew?)

@alexcrichton
Copy link
Member

While not quite the same, looks like libuv has run across the same issue

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 7, 2014
Apparently windows doesn't like reading from stdin with a large buffer size, and
it also apparently is ok with a smaller buffer size. This changes the reader
returned by stdin() to return an 8k buffered reader for stdin rather than a 64k
buffered reader.

Apparently libuv has run into this before, taking a peek at their code, with a
specific comment in their console code saying that "ReadConsole can't handle big
buffers", which I presume is related to invoking ReadFile as if it were a file
descriptor.

Closes rust-lang#13304
@klutzy
Copy link
Contributor

klutzy commented Apr 7, 2014

Wow!
msdn ReadFile page also has similar user report: "In some cases if the value is 'too big' ReadFile(...) will return ERROR_INVALID_PARAMETER."

@BrianOtto
Copy link

I just wanted to say thank you to the guys who researched and resolved this. I see the latest Windows Installer has the update in it and my example code now works in Windows 7. That was a quick turn around, thanks!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants