From: Tom Clegg Date: Tue, 21 Jan 2020 16:34:57 +0000 (-0500) Subject: 12308: Avoid returning partial reads before EOF. X-Git-Tag: 2.1.0~297^2~13 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/44ddbde1cd9945778ed7e4ae1d96c65e24f17742 12308: Avoid returning partial reads before EOF. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- diff --git a/lib/mount/fs.go b/lib/mount/fs.go index 5b6fc0012f..774948f574 100644 --- a/lib/mount/fs.go +++ b/lib/mount/fs.go @@ -320,6 +320,16 @@ func (fs *keepFS) Read(path string, buf []byte, ofst int64, fh uint64) (n int) { return fs.errCode(err) } n, err := f.Read(buf) + for err == nil && n < len(buf) { + // f is an io.Reader ("If some data is available but + // not len(p) bytes, Read conventionally returns what + // is available instead of waiting for more") -- but + // our caller requires us to either fill buf or reach + // EOF. + done := n + n, err = f.Read(buf[done:]) + n += done + } if err != nil && err != io.EOF { log.Printf("error reading %q: %s", path, err) return fs.errCode(err)