fzf: [Ubuntu] --preview error : Failed to read /dev/tty

  • Category
    • [x ] fzf binary
    • fzf-tmux script
    • Key bindings
    • Completion
    • Vim
    • Neovim
    • Etc.
  • OS
    • [x ] Linux
    • Mac OS X
    • Windows
    • Windows Subsystem for Linux
    • Etc.
  • Shell
    • [ x] bash
    • zsh
    • fish

When I use --preview I got the error message: Failed to read /dev/tty

$ echo "hello" | fzf
hello
$ echo "hello" | fzf --preview 'echo {}'
Failed to read /dev/tty
$ echo $TERM
xterm-256color
$ tty
/dev/pts/6
$ fzf --version
0.17.5 (b46227d)
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 58
  • Comments: 70 (3 by maintainers)

Commits related to this issue

Most upvoted comments

As a working fzf in vim is such an important part of my daily work I ended up rolling back the kernel

Installing the hardware enablement stack for 18.04 seems to fix the issue. The packages are: linux-image-generic-hwe-18.04 linux-headers-generic-hwe-18.04

I have just run into the same problem. The problem occurred just after a system update. System is ubuntu 18.04 LTS. Before the system update, everything worked flawlessly. Symptoms:

  1. When entering ALT-C (default binding), system responded by printing the message “Failed to read /dev/tty”.
  2. When entering /dev/tty, system responded by printing “bash: /dev/tty: Permission denied”
  3. When entering tty, system responded by printing “/dev/pts/1”

“sudo chmod 777 /dev/tty” won’t make a difference. uninstalling/reinstalling won’t make a difference.

The other commands CTRL-R and CTRL-T work without any problems.

Any help will be appreciated. Thanks.

I’ve no idea if this will work for other people, but I think I’ve found a workaround (plus it’s a good solution in general anyway).

My usage of FZF with <kbd>Ctrl</kbd> + <kbd>R</kbd> has always worked fine - so it’s not FZF that’s necessarily the problem but the command it’s calling. Today randomly I switched to using fd (https://github.com/sharkdp/fd) for my FZF search and FZF now seems to happily work even on 4.15.0-45-generic.

Once you’ve installed fd you can try putting this in your .bashrc, restart your terminal and see if fzf works again:

    export FZF_DEFAULT_COMMAND='fd --hidden --exclude ".git" .';
    export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"

Interesting, I’m using neovim and was seeing the problem

Hey Ubuntu users (16.04 and 18.04), you can help Ubuntu team release the fix. See:

For those using Ubuntu a related fix has being released in kernel version 4.18.0-15.16, hopefully that will resolve this problem

http://changelogs.ubuntu.com/changelogs/pool/main/l/linux/linux_4.18.0-15.16/changelog

linux (4.18.0-15.16) cosmic; urgency=medium

  * Userspace break as a result of missing patch backport (LP: #1813873)
    - tty: Don't hold ldisc lock in tty_reopen() if ldisc present

 -- Stefan Bader <stefan.bader@canonical.com>  Thu, 07 Feb 2019 11:24:34 +0100

Not that I know what I’m doing but sudo chmod 660 /dev/tty solved what appeared to be a similar problem on my Ubuntu 16.04 4.15.0-1027-gcp machine.

Was experiencing the issue in both nvim and using the cmdline (bash -c "sleep 1; bash -c 'echo hello'" | fzf) on kernel 4.15 I installed @shuhaowu packages, restarted, and both nvm and cmdline work. uname-r is showing 4.18.0-15-generic which seems consistent with updating the kernel directly via @emont01 solution.

With some trial and error, I’ve found that this can reliably reproduce the issue:

bash -c "sleep 1; bash -c 'echo hello'" | fzf

Kernel version updated to 4.15.0-45 but that didn’t help. Updated FZF to the latest. Still seeing the error randomly.

I’m seeing this too. It appears to have started after an Ubuntu 18.04 kernel update to 4.15.0-44. Booting back into the previous 4.15.0-43 kernel and the error does not happen.

fixed by

apt install linux-image-generic-hwe-18.04 linux-headers-generic-hwe-18.04
apt update -y && apt upgrade -y
reboot

I was running 4.15.0-45-generic and fzf was working with Bash, but was getting this error with Fish:

Failed to read /dev/tty

However, fzf is now working after following @shuhaowu’s advice and installing:

sudo apt install linux-image-generic-hwe-18.04 linux-headers-generic-hwe-18.04

Although I’m not quite sure what this does, apart from possibly changing my kernel to a completely different version.

$ uname -r
4.18.0-15-generic

On ubuntu 16.04, I downgrade to linux-image-4.4.0-141 sloved this problem.

sudo apt remove linux-image-4.4.0-142-generic linux-headers-4.4.0-142

I’ve confirmed that:

  1. If I remove my use of fd fix then I get the error
  2. If I turn on proposed releases (in Software & Updates > Developer Options), do an update to 4.15.0-46-generic and then restart I no longer get the error
uname -a
Linux ICT0115123 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I’ve also just spotted that in @junegunn 's comment the status of the bug has been updated to verified. 🎉

The solution / workaround by @shuhaowu works for me too (after a reboot) in tmux under Ubuntu 18.04 - upgraded to kernel 4.18.0-15-generic. Did the trick for both inside of Vim and on Bash 4.4.19.

For those using Ubuntu a related fix has being released in kernel version 4.18.0-15.16, hopefully that will resolve this problem

http://changelogs.ubuntu.com/changelogs/pool/main/l/linux/linux_4.18.0-15.16/changelog

linux (4.18.0-15.16) cosmic; urgency=medium

  * Userspace break as a result of missing patch backport (LP: #1813873)
    - tty: Don't hold ldisc lock in tty_reopen() if ldisc present

 -- Stefan Bader <stefan.bader@canonical.com>  Thu, 07 Feb 2019 11:24:34 +0100

Just updated ubuntu 18.04 to kernal 4.18.20 and fzf now works

@nzxcr no the hardware enablement isn’t a proper solution. There’s a fix in the kernel, it just needs verification on 18.04. See @junegunn 's comment. But if it’s not verified by testers by Monday they’ll drop the bug fix.

The same error is on Ubuntu 16.04.

$ uname -r
4.15.0-45-generic

Doing sudo chmod 600 /dev/tty also breaks tig, which apparently expects 666 as the file permission.

For Ubuntu 14.04 with a 4.4.0 Kernel, the package 4.4.0-143.169, released last Friday, fixes the bug.

This bug was fixed in the package linux - 4.4.0-143.169 linux (4.4.0-143.169) xenial; urgency=medium

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1814647

From Ubuntu’s documentation LTS Enablement Stacks, the recommended way to install a hardware enablement stack is as follows:

sudo apt install --install-recommends linux-generic-hwe-18.04

I am not convinced that this is a proper solution. Either the kernel developers introduced a necessary change, a bug with an update, or a piece of software (fzf in this case) is using a feature in perhaps the wrong way; remember that kernel developers are very anal when it comes to not breaking userspace.

@nickgronow It appears that the fix was already released for Cosmic. See https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1813873/comments/21

Simple fix is to read tty again. Maybe retries do not have to be normally, but in this case it solves the problem without going for an older kernel 😃 (see #1495)

I also still have it. uname -a 5.3.11-050311-generic SMP Tue Nov 12 21:37:23 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

I was bitten by this on 14.04 4.4.0-142. Downgrading to 4.4.0-141 resolved the issue

I as well can confirm that upgrading to 4.15.0-46 fixes this regression.

I have the same issue on ubuntu $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.2 LTS Release: 18.04 Codename: bionic

$ uname -r 4.15.0-45-generic

I got “Failed to read /dev/tty” in bash. and then I install a shell of fish to run fzf, it works for the first time. and it failed with the same error message for the second time. I don’t know why, everything works fine in tmux.

And I think it might cause more problem using specific version of kernel by:

sudo apt install linux-image-generic-hwe-18.04 linux-headers-generic-hwe-18.04

sudo chmod 660 /dev/tty works for me too, but then ssh does not work for me 😆

ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory
Permission denied, please try again.

When I change it back to 666 (as it was), ssh works but fzf does not.

Update: This has been working for me the whole day so far.

The bash -c "sleep 1; bash -c 'echo hello'" | fzf will still give an error, but that seems unrelated. Perhaps that gave an error before this bug occurred as well.

I had to bump the retries to 10 in @jerdna-regeiz’s workaround to make it consistently work on 4.15.0-45-generic.

Probably not something that should be integrated into junegunn:master, but a useful workaround until Ubuntu can push out an updated kernel.

With kernal 4.15.0-45 the problem appears to be worse for me. Simply running fzf in the terminal or in vim/neovim fails now. I had one successful attempt in about 20.

@vhakulinen your findings are consistent with the ubuntu kernel bug linked above. It mentions:

a rather serious regression where userspace applications reading
from stdin can receive EAGAIN when they should not

I see the bug has been marked Fix Committed but I think it may not have been released yet. I find Launchpad pretty confusing when it comes to figuring this kind of thing out. I guess we’ll see with the next kernel update.

After doing some research, every time I get Failed to read /dev/tty, this returns syscall.EAGAIN. ~This probably means that the operation needs to be tried again: https://stackoverflow.com/questions/4058368/what-does-eagain-mean~

Confirmed that booting Ubuntu kernel 4.15.0-43 allows fzf to work properly. For now have uninstalled 4.15.0-44 and am booting previous kernel.