hyperhq / runv

Hypervisor-based Runtime for OCI
Apache License 2.0
826 stars 129 forks source link

Bug fix: runv-contianerd hangs when no terminal #265

Closed WeiZhang555 closed 8 years ago

WeiZhang555 commented 8 years ago

Fixes https://github.com/hyperhq/runv/issues/210

When trying to interact between docker and runv-containerd, if docker specify no terminal, client can't exit and everything hangs.

This is caused by blocked stderr pipe, if docker specify no terminal, docker will open reader side of stderr pipe, but runv-containerd never open write side of stderr side, which causes everything to hanging state.

Signed-off-by: Zhang Wei zhangwei555@huawei.com

WeiZhang555 commented 8 years ago

Reproduce steps:

1. start runv-containerd:
$ ./runv-containerd --debug ....

2. start docker daemon:
$ dockerd -D --containerd /run/runv-containerd/containerd.sock ......

3. try to start a container without tty
$ docker run -i --name test busybox sh
pwd
/
exit 11
<hanging...>

4. in another terminal, try to stop or ps container
$ docker stop test
<hanging...>
$ docker ps
<hanging...>

Reference code of docker: https://github.com/docker/docker/blob/master/libcontainerd/process_linux.go#L49-L53

If container has a TTY, then its stderr is only emptyReader, but without TTY, it opens stderr pipe file and tries to read data from pipe. As runv-containerd never hands stderr pipe, docker hangs.

That's why docker run -ti xxx works fine but docker run -i xxx won't.

WeiZhang555 commented 8 years ago

Already fixed, close this.