Skip to content

Closed standard file descriptors don't generate errors anymore on Unix #88825

Open
@Alphare

Description

@Alphare

I've found that #75295 introduced a regression in the "Rust first then fallback to Python" version of the Mercurial test suite.

I was testing if going from 1.41.1 (previous Debian stable version) to 1.48.0 broke anything, and it appears it did. This test checks that closed file descriptors raise an acceptable error, and this does not happen anymore. Here is the fallback code for rhg, running the Python version of hg as a subprocess.

Here is the (somewhat convoluted) reproduction, which requires python be a valid Python 3 interpreter that I used with cargo bisect-rust (thanks @SimonSapin for the pointer on that tool btw):

//! Run the executable (not with `cargo play`, it'll eat the redirect)
//!     `myexecutable -c 'import sys; sys.stdout.write("hello")' 1>&-`
//! If compiled with 1.41.1, it will output (with an error code of 1):
//!
//! Traceback (most recent call last):
//!  File "<string>", line 1, in <module>
//!  AttributeError: 'NoneType' object has no attribute 'write'
//!
//! But with 1.48.0, it doesn't output anything and silently eats the error code,
//! exiting with 0.

use std::process::Command;

fn main() {
    let mut args_os = std::env::args_os();
    args_os.next().expect("expected argv[0] to exist");
    let mut c = Command::new("python");
    c.args(args_os);
    let status = c.status();
    match status {
        Err(_) => (),
        Ok(s) =>  {
            if s.success() {
                std::process::exit(1);
            }
        }
    }
}

I'm not 100% sure what to think of it yet, but my gut feeling is that eating errors is bad; I'm reporting this now since it's fresh in my mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-discussionCategory: Discussion or questions that doesn't represent real issues.O-unixOperating system: Unix-likeT-libsRelevant to the library 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