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

Rustyline crashes in linux if you hold enter #291

Closed
sophiajt opened this issue Oct 17, 2019 · 14 comments
Closed

Rustyline crashes in linux if you hold enter #291

sophiajt opened this issue Oct 17, 2019 · 14 comments
Labels

Comments

@sophiajt
Copy link

Repro:

> cargo run --example example
1> [now hold enter here]

Once you hold enter, after a few seconds you'll see:

1> 
Line: 
2> 
Line: 
3> 
Line: 
4> 
Line: 
5> 
Line: 

Error: Io(Kind(InvalidData))
@gwenn
Copy link
Collaborator

gwenn commented Oct 17, 2019

Sorry,
I cannot reproduce.

  • x86_64-apple-darwin / rustc 1.40.0-nightly (c27f7568b 2019-10-13) (macOS Catalina)
  • x86_64-unknown-linux-gnu / rustc 1.38.0 (625451e37 2019-09-23) (archlinux VM)

@gwenn gwenn added the bug label Oct 17, 2019
@sophiajt
Copy link
Author

My platform:

Linux pop-os 5.0.0-25-generic #26-Ubuntu SMP Thu Aug 1 12:04:58 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
rustc 1.39.0-nightly (521d78407 2019-08-25)

@gwenn
Copy link
Collaborator

gwenn commented Oct 17, 2019

I've also tried rustc on linux but still no error:
I guess that the VM/VirtualBox layer prevents me to reproduce the bug.

@sophiajt
Copy link
Author

That could be it. My guess is that it comes from the speed that the enter is happening, so trying it on a native install of Linux might be the best way to try to repro.

@Detegr
Copy link

Detegr commented Oct 17, 2019

@jonathandturner which terminal and shell are you using? My machine is native Arch Linux Linux 5.3.5-arch1-1-ARCH #1 SMP PREEMPT Mon Oct 7 19:03:08 UTC 2019 x86_64 GNU/Linux, compiled with rustc 1.39.0-nightly (9eae1fc0e 2019-08-23) and I'm unable to repro this in Alacritty or xterm, zsh/bash. I tried setting key repeat to an absurdly high value with xset r rate 200 250 but it does not have any effect.

@sophiajt
Copy link
Author

I can't repro in alacritty, but I can repro inside the default GNOME terminal for Pop! OS (an Ubuntu-based distro)

@gwenn
Copy link
Collaborator

gwenn commented Oct 18, 2019

@jonathandturner Would you mind trying to generate a backtrace (RUST_BACKTRACE=1) ?

@sophiajt
Copy link
Author

@gwenn - it panics without a backtrace, but experimenting a bit, I see that it's originating here:

return Err(error::ReadlineError::from(io::ErrorKind::InvalidData));

@sophiajt
Copy link
Author

With a bit more experimenting: I understand that this is verifying that you should be properly reset, but commenting it out doesn't seem to show any issues of not getting reset correctly:

rustyline/src/tty/unix.rs

Lines 688 to 699 in 39f3578

if rdr.next_char()? != '\x1b' {
return Err(error::ReadlineError::from(io::ErrorKind::InvalidData));
}
if rdr.next_char()? != '[' {
return Err(error::ReadlineError::from(io::ErrorKind::InvalidData));
}
read_digits_until(rdr, ';')?;
let col = read_digits_until(rdr, 'R')?;
debug!(target: "rustyline", "initial cursor location: {:?}", col);
if col != 1 {
self.write_and_flush(b"\n")?;
}

I was wondering what kinds of issues this was trying to protect from. Maybe there's another way to do it?

@gwenn
Copy link
Collaborator

gwenn commented Oct 20, 2019

My wild guess is that we receive Enter/'\r' instead of Esc/\x1b because the key press happens after:

if rdr.poll(0)? != 0 {

But before:
self.write_and_flush(b"\x1b[6n")?;

We can still ignore unexpected/user input in this case.

@gwenn
Copy link
Collaborator

gwenn commented Oct 20, 2019

See #292

@gwenn
Copy link
Collaborator

gwenn commented Oct 20, 2019

Liner seems to always write "⏎":
https://github.com/redox-os/liner/blob/master/src/editor.rs#L156

@sophiajt
Copy link
Author

@gwenn - I tried out #292 and it fixes the issue for me.

@gwenn
Copy link
Collaborator

gwenn commented Oct 30, 2019

Fix by release 5.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants