expectrl: sleep() before interactive() causes freeze

The code below run as expected, printing the git diff help, then result StillAlive, then exiting.

fn main() {
    let mut cmd = std::process::Command::new("git");
    cmd.args(["diff"]);
    cmd.current_dir("/tmp");
    let mut session = expectrl::Session::spawn(cmd).expect("Can't spawn a session");
    let mut opts = expectrl::interact::InteractOptions::terminal().unwrap();
    let res = opts.interact(&mut session).unwrap();
    println!("result {:?}", res);
}

This code freezes, printing nothing and not exiting:

fn main() {
    let mut cmd = std::process::Command::new("git");
    cmd.args(["diff"]);
    cmd.current_dir("/tmp");
    let mut session = expectrl::Session::spawn(cmd).expect("Can't spawn a session");
    std::thread::sleep(std::time::Duration::from_millis(300));
    let mut opts = expectrl::interact::InteractOptions::terminal().unwrap();
    let res = opts.interact(&mut session).unwrap();
    println!("result {:?}", res);
}

Hitting return causes the program to continue as before. It seems like the delay is causing expectrl to enter the interactive mode in a blocking way, but that’s not quite right because interactive mode should require ^] to exit, not just a return. Also, there’s no input command here awaiting a return.

The expected behavior would be that the output is exactly as before but delayed 300ms.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

Once again just for an update, I haven’t found a solution for this “bug” yet.

But it is 100% related to a core pty lib.

Only found a similar issue in a https://github.com/creack/pty/issues/101 which seems to be unresolved fully.

Froze! Waited more than 5m.

    Running tests/io.rs (target/debug/deps/io-c034048bff565ae5)

running 1 test
test try_read_after_process_exit has been running for over 60 seconds
^C
$  git clone https://github.com/zhiburt/expectrl.git && cd expectrl && cargo test
...
running 15 tests
test check_macros::tests::test_check ... ignored
test expect::tests::test_n_bytes ... ok
test expect::tests::test_eof ... ok
test expect::tests::test_bytes ... ok
test expect::tests::test_bytes_ref ... ok
test expect::tests::test_byte ... ok
test tests::session_as_writer ... ignored
test expect::tests::test_str ... ok
test expect::tests::test_any ... ok
test interact::tests::contains_in_bytes_test ... ok
test expect::tests::test_char ... ok
test session::tests::test_iterator_on_found ... ok
test tests::test_spawn_no_command ... ok
test tests::test_tokenize_command ... ok
test expect::tests::test_regex ... ok

test result: ok. 13 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.04s

    Running tests/check.rs (target/debug/deps/check-523dee5bbc96a0c4)

running 10 tests
test check_eof_timeout ... ok
test check_str ... ok
test check_macro_eof ... FAILED
test check_eof ... FAILED
test read_after_check_str ... ok
test check_n_bytes ... ok
test check_macro ... ok
test check_regex ... ok
test check_macro_with_different_needles ... ok
test check_macro_doest_consume_missmatch ... ok

failures:

---- check_macro_eof stdout ----
thread 'check_macro_eof' panicked at 'Unexpected result', tests/check.rs:253:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- check_eof stdout ----
thread 'check_eof' panicked at 'index out of bounds: the len is 0 but the index is 0', src/session.rs:743:18


failures:
    check_eof
    check_macro_eof

test result: FAILED. 8 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.31s

error: test failed, to rerun pass '--test check'
$

Will do…