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

program dies silently when doing I/O on a defunct child Process #13123

Closed
japaric opened this issue Mar 25, 2014 · 4 comments · Fixed by #13158
Closed

program dies silently when doing I/O on a defunct child Process #13123

japaric opened this issue Mar 25, 2014 · 4 comments · Fixed by #13158

Comments

@japaric
Copy link
Member

japaric commented Mar 25, 2014

Scripts to reproduce

// loopback.rs
use std::io::stdio::stdin;

fn main() {
    for line in stdin().lines() {
        match line {
            Ok(line) => print!("{}", line),
            Err(e)   => fail!("whoops: {}", e),
        }
    }
}
// process-fail.rs
use std::io::process::Process;
use std::io::timer::Timer;

fn main() {
    let mut timer = Timer::new().unwrap();
    let periodic = timer.periodic(1000);

    let mut child = Process::new("./loopback", []).unwrap();
    let mut count = 10;

    println!("write to child process in")
    while count > 0 {
        println!("{}", count);
        count -=1;

        periodic.recv();
    }

    match child.stdin.get_mut_ref().write_str("Hello world!\n") {
        Ok(_)  => println!("succeed"),
        Err(_) => fail!("whoops"),
    }

    println!("end of main");
}

Steps to reproduce:

$ ./process-fail
$ killall loopback  # before countdown ends

Output:

Backtrace: None
Exit code: 141

Version:

rustc 0.10-pre (e6468a8 2014-03-24 10:01:57 -0700)
host: x86_64-unknown-linux-gnu
@alexcrichton
Copy link
Member

What are you expecting to happen? When you send a TERM signal to a process without a registered handler, it terminates promptly. The runtime currently doesn't register any TERM/INT handlers, that's up to you.

@japaric
Copy link
Member Author

japaric commented Mar 25, 2014

What are you expecting to happen?

I was expecting the runtime to return some Err() upon requesting an action from a defunct process. I also tried polling the state of the defunct process using signal(0) (as mentioned in the documentation), but this returned Ok() as well.

When you send a TERM signal to a process without a registered handler, it terminates promptly. The runtime currently doesn't register any TERM/INT handlers, that's up to you.

Even if the runtime dosn't "catch" the SIG{TERM,INT}, is it not possible at all to fail!() or return Err() in any of the two cases mentioned above?

@alexcrichton
Copy link
Member

Oh whoops, sorry! I had my understanding backwards, and apparently this isn't a bug on OSX which caused more confusion for me.

Anyway, closing as a dupe of #13124, it's the same cause.

@japaric japaric changed the title program dies silently if child Process was killed externally program dies silently when doing I/O on a defunct child Process Mar 26, 2014
@alexcrichton
Copy link
Member

Oh wow, I've done it again. I'm sorry, again! I apologize for not investigating more thoroughly.

This is indeed separate from #13124

@alexcrichton alexcrichton reopened this Mar 26, 2014
bors added a commit that referenced this issue Mar 28, 2014
Some unix platforms will send a SIGPIPE signal instead of returning EPIPE from a
syscall by default. The native runtime doesn't install a SIGPIPE handler,
causing the program to die immediately in this case. This brings the behavior in
line with libgreen by ignoring SIGPIPE and propagating EPIPE upwards to the
application in the form of an IoError.

Closes #13123
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants