Skip to content

A call to BufReader<File>::lines().count() on a non-read opened file in Linux never returns. #34703

Closed as not planned
@joelself

Description

@joelself

Not much to it. I have this bit of code:

fn get_line_count(file_name: String) -> Result<usize, Error> {
    let file = try!(OpenOptions::new().append(true).create(true).open(&file_name));
    let f = BufReader::new(file);
    Ok(f.lines().count())
}

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):

ls -la new_chunks.txt 
-rw-rw-r-- 1 joel joel 0 Jul  7 07:38 new_chunks.txt

My program wasn't going anywhere, but it was using up 100% of one core. Some printlns later and I found that it couldn't get past Ok(f.lines().count()). Specifically it was the call to count() that wasn't returning.

This is Ubuntu 14.04. rustup show:

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.9.0 (e4e8b6668 2016-05-18)

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:

beta-x86_64-unknown-linux-gnu (directory override for '/home/joel/dirname/dirname/project')
rustc 1.11.0-beta.1 (8dc253bcf 2016-07-05)

nightly-x86_64-unknown-linux-gnu (directory override for '/home/joel/dirname/dirname/project')
rustc 1.11.0-nightly (696b703b5 2016-07-03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions