withoutboats / notty

A new kind of terminal
GNU Affero General Public License v3.0
2.31k stars 41 forks source link

Ctrl-D causes a panic #30

Closed pscollins closed 8 years ago

pscollins commented 8 years ago

Trying to quit the shell with Ctrl-D out of habit, I got the following stack trace:

➜  scaffolding git:(master) RUST_BACKTRACE=1 cargo run
     Running `target/debug/scaffolding-terminal`
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 5, message: "Input/output error" } }', ../src/libcore/result.rs:746
stack backtrace:
   1:     0x7ffb5339f240 - sys::backtrace::tracing::imp::write::h7af3c3cfd3e65a783bv
   2:     0x7ffb533a1b2b - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44497
   3:     0x7ffb533a1798 - panicking::default_handler::h75ebcc0c8bcd1085rRz
   4:     0x7ffb53397eac - sys_common::unwind::begin_unwind_inner::hcec45e84262f1855m0t
   5:     0x7ffb533982f8 - sys_common::unwind::begin_unwind_fmt::h62c174e37e54c321sZt
   6:     0x7ffb5339e6b1 - rust_begin_unwind
   7:     0x7ffb533d0e7f - panicking::panic_fmt::h5f920bbc722cd548lcM
   8:     0x7ffb532e106b - result::unwrap_failed::h14713097509445665626
                        at ../src/libcore/macros.rs:29
   9:     0x7ffb532ee0cb - result::Result<T, E>::unwrap::h4578224278132733853
                        at ../src/libcore/result.rs:687
  10:     0x7ffb532e288a - main::_$u7b$$u7b$closure$u7d$$u7d$::closure.10320
                        at src/main.rs:67
  11:     0x7ffb532e21c0 - std::thread::Builder::spawn::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::closure.10309
                        at ../src/libstd/thread/mod.rs:277
  12:     0x7ffb532e2169 - sys_common::unwind::try::try_fn::h14296686403988533152
                        at ../src/libstd/sys/common/unwind/mod.rs:127
  13:     0x7ffb5339e63b - __rust_try
  14:     0x7ffb5339c20d - sys_common::unwind::inner_try::h27915955daa5bb0coXt
  15:     0x7ffb532e20ce - sys_common::unwind::try::h12233384044057444796
                        at ../src/libstd/sys/common/unwind/mod.rs:123
  16:     0x7ffb532e1f40 - std::thread::Builder::spawn::_$u7b$$u7b$closure$u7d$$u7d$::closure.10284
                        at ../src/libstd/thread/mod.rs:277
  17:     0x7ffb532e2c0c - boxed::F.FnBox<A>::call_box::h7394299706424739120
                        at ../src/liballoc/boxed.rs:541
  18:     0x7ffb533a06a9 - sys::thread::Thread::new::thread_start::h47cad50136a0a353LOy
  19:     0x7ffb50770181 - start_thread
  20:     0x7ffb50f9247c - __clone
  21:                0x0 - <unknown>

It looks like the issue is in scaffolding/src/main.rs at:

    thread::spawn(move || {
        let output = Output::new(BufReader::new(tty_r));
        for cmd in output {
            tx_out.send(cmd.unwrap()).unwrap();
        }
    });

Because I suppose in src/output/mod.rs, Output::next is returning None.

withoutboats commented 8 years ago

This also occurs if you exit the shell using exit. On my system at least, nothing panics until you type additional input. Is this true for you as well?

More broadly, the issue here is that the process needs to exit gracefully when the tty is closed by the shell, and currently it doesn't react to that event at all. As a result, it panics eventually when some invariant is violated because the tty is closed.

waynr commented 8 years ago

Reopening since this behavior hasn't been fixed. I just opened a PR that I think should do the trick.

ghost commented 8 years ago

adding a link to said PR https://github.com/withoutboats/notty/pull/35

withoutboats commented 8 years ago

This is now fixed properly.