clearcontainers / runtime

OCI (Open Containers Initiative) compatible runtime using Virtual Machines
Apache License 2.0
589 stars 70 forks source link

Failed to handle stdin with `docker exec -i` #612

Open jcvenegas opened 7 years ago

jcvenegas commented 7 years ago

The following case is failing trying to send some date by through a pipe.

echo data | docker exec -i "${container}" bash -c "cat > /f"

Here a script to run and confirm. Note that it works for runc as runtime.

#!/bin/bash
content="test"

test_stdin() {
runtime=$1
#Run a container to run for 30 seconds
docker run --rm --runtime "${runtime}" -d ubuntu bash -c "sleep 30"
last_container=$(docker ps -l -q)
#Send by stdin to text to container | the container will save it in a file
echo $content | docker exec -i "${last_container}" bash -c "cat > /f"
#Check the file has the cogent previously saved 
docker exec -i "${last_container}" bash -c "cat /f" | grep "${content}" || echo "failed"
}

echo "Check with runc"
test_stdin "runc"
echo "Check with cc-runtime"
test_stdin "cc-runtime"
jcvenegas commented 7 years ago

this is a regression from 2.x to 3.0

jcvenegas commented 7 years ago

From @amshinde "I tried reproducing the issue and was able to do so. The command just hangs. But I do see that the file is successfully created inside the container with the right content, the container process does not seem to send the exit code to the shim process. I can verify this from the shim logs as well, the contents of the file are sent, but it never receives an exit code."

sboeuf commented 6 years ago

@jcvenegas good news, https://github.com/clearcontainers/proxy/pull/170 and https://github.com/clearcontainers/agent/pull/162 fix this issue. The root cause was both the proxy not redirecting empty messages, and the agent not handling the closure of stdin in such cases.

sboeuf commented 6 years ago

@jcvenegas I think this issue could be closed since clearcontainers/proxy#170 and clearcontainers/agent#162 have been merged. We might want to wait for the agent patch to reallly land into our clear-containers.img though.