-
Notifications
You must be signed in to change notification settings - Fork 13.4k
A call to BufReader<File>::lines().count() on a non-read opened file in Linux never returns. #34703
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
Comments
let mut f = BufReader::new(file);
let mut count = 0;
let mut line = String::new();
if let Ok(mut bytes) = f.read_line(&mut line) {
while bytes > 0 {
// Do something with the line
count += 1;
line.clear();
match f.read_line(&mut line) {
Ok(b) => bytes = b,
Err(_) => {},
}
}
} Edit: Alternatively, if you want to open a file for read you could, you know, just open the file for read I guess. If you're into that sort of thing. |
This appears to be a few things at play:
The "fix" here would be to fuse the |
Ah, this the first time I tried |
Closing this as this error was formed due to a misuse of the API |
Coming here from #64144. The example code here is old, but I've updated it and it still behaves the same. Eyeballing the code it seems harmless, so it is unfortunate that it is an infinite loop.
|
Uh oh!
There was an error while loading. Please reload this page.
Not much to it. I have this bit of code:
And I'm passing in a file that exists, but is empty (actually, by the timestamp, the file probably didn't exist until the first line in the function created it):
My program wasn't going anywhere, but it was using up 100% of one core. Some
println
s later and I found that it couldn't get pastOk(f.lines().count())
. Specifically it was the call tocount()
that wasn't returning.This is Ubuntu 14.04.
rustup show
:Edit: This was running in release mode, but I confirmed it in debug mode too. I also tried the current beta and nightly channels in release and debug mode:
The text was updated successfully, but these errors were encountered: