From 69294cf98aa82f37330bc7fba53bc2c8a29605fd Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 1 Dec 2023 16:13:19 -0800 Subject: [PATCH] Disable DMA optimization on windows (#18575) It appears that Windows can lock up when errors occur. Use regular copy here. --- cmd/storage-rest-server.go | 4 +++- internal/http/response-recorder.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index e6322804c..dff9a7233 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -29,6 +29,7 @@ import ( "net/http" "os/user" "path" + "runtime" "runtime/debug" "strconv" "strings" @@ -641,9 +642,10 @@ func (s *storageRESTServer) ReadFileStreamHandler(w http.ResponseWriter, r *http defer rc.Close() rf, ok := w.(io.ReaderFrom) - if ok { + if ok && runtime.GOOS != "windows" { // Attempt to use splice/sendfile() optimization, A very specific behavior mentioned below is necessary. // See https://github.com/golang/go/blob/f7c5cbb82087c55aa82081e931e0142783700ce8/src/net/sendfile_linux.go#L20 + // Windows can lock up with this optimization, so we fall back to regular copy. dr, ok := rc.(*xioutil.DeadlineReader) if ok { sr, ok := dr.ReadCloser.(*sendFileReader) diff --git a/internal/http/response-recorder.go b/internal/http/response-recorder.go index 72622601a..cb630a483 100644 --- a/internal/http/response-recorder.go +++ b/internal/http/response-recorder.go @@ -80,7 +80,9 @@ var ErrNotImplemented = errors.New("not implemented") // returns an error if the underlying ResponseWriter does not implement io.ReaderFrom func (lrw *ResponseRecorder) ReadFrom(r io.Reader) (int64, error) { if lrw.ReaderFrom != nil { - return lrw.ReaderFrom.ReadFrom(r) + n, err := lrw.ReaderFrom.ReadFrom(r) + lrw.bytesWritten += int(n) + return n, err } return 0, ErrNotImplemented }