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

On macOS, prompt exits if background command terminates #211

Open
LucasPickering opened this issue May 20, 2024 · 0 comments
Open

On macOS, prompt exits if background command terminates #211

LucasPickering opened this issue May 20, 2024 · 0 comments

Comments

@LucasPickering
Copy link

I'm experience a strange interaction between console (used via dialoguer) and tokio's Command interface. I've done my best to debug it, but please let me know if there are more steps I can take that would be helpful.

Reproduction

Here's a simple reproduction (I've uploaded the full thing as a repo if that's easier):

use console::Term;
use std::process::Stdio;
use tokio::process::Command;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let term = Term::stderr();
    let mut child = Command::new("sleep")
        .arg("2")
        .stdin(Stdio::null())
        .stdout(Stdio::null())
        .stderr(Stdio::null())
        .spawn()
        .unwrap();
    let response = term.read_line().unwrap();
    child.wait().await.unwrap();
    println!("{response}");
}

Desired Behavior

The prompt should remain open indefinitely, until the user hits Enter. At that point, it should echo back whatever input was given.

Observed Behavior

The prompt remains open for 2 seconds, then closes and the program terminates with exit code 130 (indicating SIGINT).

  • If you type something then hit Enter before the background command exits, you'll see it pause until the 2 second sleep is complete, then output is echoed back as expected.
  • If you type something but do not hit enter before the background command exits, you will not see the echoed output. It exits immediately, as if SIGINT was received.

While waiting for input, console is blocked on this call to libc::select in select_fd, which explains why this issue is specific to macOS.

Other Context

The error does not occur in the following scenarios:

  • Using std::process::Command instead of tokio's Command (even if you spawn the process in the background while running the prompt)
  • Using term.read_secure_line()
  • On Linux, according to a user of my app. This is consistent with the fact that console is stopped in macos-only code at the time of termination.

Versions

I am running:

  • MacOS 14.4.1
  • iTerm2 3.4.23
  • console 0.15.8
  • tokio 1.37.0
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

No branches or pull requests

1 participant