Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1113608 - `docker attach` hangs when attaching container, which is exiting
`docker attach` hangs when attaching container, which is exiting
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: docker (Show other bugs)
7.0
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Lokesh Mandvekar
Virtualization Bugs
: Extras
Depends On:
Blocks: 1138364
  Show dependency treegraph
 
Reported: 2014-06-26 09:50 EDT by Lukas Doktor
Modified: 2015-03-04 22:19 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-03-04 22:19:04 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:0623 normal SHIPPED_LIVE Low: docker security, bug fix, and enhancement update 2015-03-05 10:28:35 EST

  None (edit)
Description Lukas Doktor 2014-06-26 09:50:03 EDT
Description of problem:
When you execute `docker attach` on a container, which is in the process of shutting down, the process doesn't fail, but hangs for ever.

Even when you remove (`docker rm`) the container afterwards, the process still exists and when you use eg. ctrl+c, it complains about missing container.

When you have stdin attached, it finishes after an input, otherwise you have to use `kill -9` to get rid of it.

Version-Release number of selected component (if applicable):
docker-0.11.1-10.el7.x86_64
docker-io-1.0.0-3.fc20.x86_64

How reproducible:
rarely on RHEL7 (0.11.1), always on Fedora 20 (1.0.0-3)

Steps to Reproduce:
1. in 1st terminal execute: "while :; do sudo docker -D attach  `sudo docker ps -l -q`; done"
2a. in 2nd terminal execute: "docker run -i -t fedora bash" and when the first terminal attaches, use `exit` or `ctrl+d` to stop the container.
2b. when the 2a doesn't causes the bug, use this script to start-stop containers in a loop: "while :; do ID=`docker run -d -i -t fedora bash`; sleep 1; echo exit | docker attach $ID; done"

Actual results:
On Fedora after step 2a the attach process in 1st terminal hangs, there is no new input.
On RHEL after a while while executing the 2b script, the attach process in 1st terminal hangs.

Expected results:
The attach process in 1st terminal should finish when the container is destroyed and lots of messages like:

2014/06/26 15:29:55 You cannot attach to a stopped container, start it first
2014/06/26 15:29:55 You cannot attach to a stopped container, start it first
2014/06/26 15:29:55 You cannot attach to a stopped container, start it first
2014/06/26 15:29:55 You cannot attach to a stopped container, start it first

should occur (as we are trying to attach stopped container).


Additional info:
When you use `docker attach --no-stdin ...` you can write anything. After a ctrl+c it realizes the container is not running and finishes. ctrl+p+q doesn't work. In RHEL version when you remove the container by `docker rm` first, ctrl+c generates message in docker daemon, that the container with id ... doesn't exist and the `docker attach` process is still hanged.

When you have stdin attached, after sending any character the process is destoyed with:
[debug] hijack.go:96 [hijack] End of stdout
                                           2014/06/26 15:49:31 You cannot attach to a stopped container, start it first
Comment 5 Daniel Walsh 2014-08-22 09:18:35 EDT
Upstream found a bug in docker (Caused by a fix from me) blocks interactive terminals from exiting.

Might fix this problem.
Comment 6 Lukas Doktor 2014-09-09 09:08:45 EDT
OK I tried that on F21 with docker-io-1.2.0-2.fc21.x86_64 and it works fine (no failure after couple of hours).
Comment 7 Daniel Walsh 2014-09-09 09:59:40 EDT
Great,
Comment 8 Daniel Walsh 2014-09-12 13:13:15 EDT
Fixed in docker-1.2
Comment 10 Luwen Su 2015-01-28 03:59:59 EST
With docker-1.4.1-27.el7.x86_64,
run the script
# cat 1113608.sh 
# /bin/bash
while :; do ID=`docker run -d -i -t rhel7 bash`; sleep 1; echo exit | docker attach $ID; done

generated 
FATA[0000] cannot enable tty mode on non tty input      
FATA[0000] cannot enable tty mode on non tty input 

no hang here, so move to verify
Comment 12 errata-xmlrpc 2015-03-04 22:19:04 EST
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2015-0623.html

Note You need to log in before you can comment on or make changes to this bug.