-
Notifications
You must be signed in to change notification settings - Fork 280
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
use-dev-tty causes panic #755
Comments
I did a bit of searching. Unfortunately I don't know enough about these topics. Please just ignore this if it turns out to be wrong. It might be that EINTR isn't handled correctly (or at all). Mio is returning a specific error, which is handled and ignored: crossterm/src/event/source/unix/mio.rs Lines 83 to 92 in 383d9a7
Here's the exact point where the panic occurs in the tty version. Ignoring that specific error will avoid the panic (obviously). --- a/src/event/source/unix/tty.rs
+++ b/src/event/source/unix/tty.rs
@@ -132,7 +132,24 @@ impl EventSource for UnixInternalEventSource {
}
match poll(&mut fds, timeout.leftover()) {
Err(filedescriptor::Error::Io(e)) => return Err(e),
- res => res.expect("polling tty"),
+ res => match res {
+ Ok(_res) => {}
+ Err(fd_err) => {
+ match fd_err {
+ filedescriptor::Error::Poll(err)
+ if err.kind() == io::ErrorKind::Interrupted =>
+ {
+ continue
+ }
+ other_err => {
+ // TODO:
+ // This function already returns Result<T>.
+ // So don't panic, but instead return an error!
+ panic!("{:?}", other_err)
+ }
+ }
+ }
+ },
};
if fds[0].revents & POLLIN != 0 {
loop {
|
cc @yyogo |
Thank you for the report! This is indeed due to not handling eintr correctly - I believe the correct solution is to just ignore it, since we already keep polling until we get an event or the timeout expired. |
The reason this panics btw, is that |
@markus-bauer I'm unable to reproduce the panic using your example. Can you verify it does not reproduce with #762 ? |
Don't have time right now, but will report back later. Have you tried pressing any button repeatedly, or increasing the number of tasks in the loop? It only happens after a lot of tasks are spawned. Anyway, in hindsight, I think you should be able to reproduce it if you can make anything send interrupt. |
@yyogo Okay, I did a quick test with my example code and my real code. With your patch, it no longer panics. It still panics with the old version. It's interesting that you can't reproduce this, because it happens reliably, every time. But it appears to be fixed now. Thanks for your work on this. |
Description
The new feature
use-dev-tty
sometimes causes this panic:panicked at 'polling tty: Poll(Os { code: 4, kind: Interrupted, message: "Interrupted system call" })', XXX/.cargo/registry/src/.../crossterm-0.26.0/src/event/source/unix/tty.rs:135:28 ...
crossterm/src/event/source/unix/tty.rs
Line 135 in 383d9a7
How to reproduce
I have not found a minimal example, and my full code is not public. But I can reliably trigger it with the code below:
Note that this won't panic without the tty feature. And the panic seems to only happen with this combination (task + command). I don't know enough about tokio to be of help here.
There's another problem: When the EventStream panics, it will do it silently (not counting the panic message). At that point it will stop sending events, and the main loop is just blocked forever. Shouldn't the event stream return a
Result<Event>
to handle cases where the EventSource is found to be dead? In any case, please avoid panics.Environment
I've also tested this with the current crossterm on github, with the same results.
Update:
I've changed the code to be more like the official example, which first fuses the future. This still doesn't stop the loop from being blocked after panic.
The text was updated successfully, but these errors were encountered: