hyperhq / runv

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

read until EOF in streamCopy #498

Closed bergwolf closed 7 years ago

bergwolf commented 7 years ago

If either stdoutPipe or stderrPipe reads to EOF, do not close the other one so that it can read to EOF as well. Otherwise we might lose output in the other pipe.

This works because if runv ends the stdout/stderr streams, it always closes the writer part of both pipes. Then io.Copy() will get EOF and return success here.

Also no need to wait stdin go routine because streamCopy() runs in a go routine itself thus no one is really waiting out there.

Some observations found during looking at io.Pipe() source code:

  1. reading from a write-side closed pipe returns all buffered data and then EOF
  2. reading from a read-side closed pipe returns ErrClosedPipe and no data

So streamCopy() cannot close stdout/stderr pipes from the reader side and expect io.Copy() to still read buffered data from them.

This might fix the failure in http://ci.hypercontainer.io:8080/job/hyperd-auto/404/console

gnawux commented 7 years ago

LGTM

laijs commented 7 years ago

LGTM