fix: avoid writing more content on network with O_DIRECT reads (#11659)

There was an io.LimitReader was missing for the 'length'
parameter for ranged requests, that would cause client to
get truncated responses and errors.

fixes #11651
This commit is contained in:
Harshavardhana
2021-02-28 15:33:03 -08:00
committed by GitHub
parent c67d1bf120
commit 37960cbc2f
3 changed files with 39 additions and 14 deletions

View File

@@ -40,6 +40,7 @@ import (
xhttp "github.com/minio/minio/cmd/http"
xjwt "github.com/minio/minio/cmd/jwt"
"github.com/minio/minio/cmd/logger"
xnet "github.com/minio/minio/pkg/net"
)
var errDiskStale = errors.New("disk stale")
@@ -527,7 +528,12 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http
defer rc.Close()
w.Header().Set(xhttp.ContentLength, strconv.Itoa(length))
io.Copy(w, rc)
if _, err = io.Copy(w, rc); err != nil {
if !xnet.IsNetworkOrHostDown(err, true) { // do not need to log disconnected clients
logger.LogIf(r.Context(), err)
}
return
}
w.(http.Flusher).Flush()
}