Weird piping behavior in containers

Here’s an odd one: When I chain multiple pipes inside of a container, the producer hangs indefinitely instead of exiting when the consumers stop consuming.

As a concrete example,

# yes | fold | head -n 1
y

Prints one “y” and then halts on the host, as expected. But inside of a container, this command prints one “y”, but never exits. top shows that fold is locked at 100% single-core CPU usage. Neither the shell nor the base image seem to make a difference - I have tried various combinations of Debian, Ubuntu, bash, sh, and dash.

This is version 3.18 on Fedora, installed with snap. I’d like to figure out what’s going on because this behavior breaks shell scripts.

Hi!

It looks like a tty issue.

user@mycomputer:~$ lxc exec mycontainer bash
root@mycontainer:~# yes | fold | head -n 1
y
^C
root@mycontainer:~# tty
not a tty
root@mycontainer:~# exit
user@mycomputer:~$ lxc console mycontainer
To detach from the console, press: <ctrl>+a q

mycontainer login: root
Password: 
Last login: Sun Nov  3 22:43:55 UTC 2019 on UNKNOWN
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-66-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Nov  3 22:58:27 UTC 2019

  System load:    0.16      Memory usage: 0%   Processes:       20
  Usage of /home: unknown   Swap usage:   0%   Users logged in: 0


0 packages can be updated.
0 updates are security updates.

root@mycontainer:~# yes | fold | head -n 1
y
root@mycontainer:~# tty
/dev/console
root@mycontainer:~# 
2 Likes

Brilliant! Didn’t know you could bring up a proper tty.