chore: log where and after how many bytes a file transfer breaks
This commit is contained in:
1 parent
19f8b5291e
commit
438b20dae0
2 files changed
+17
-4
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
@@ -154,7 +155,10 @@ func (s *Server) handleFSUpload(w http.ResponseWriter, r *http.Request) {
|
||||
copied := make(chan struct{})
|
||||
go func() {
|
||||
defer close(copied)
|
||||
_, err := io.Copy(st.w, body)
|
||||
n, err := io.Copy(st.w, body)
|
||||
if err != nil && !errors.Is(err, io.ErrClosedPipe) {
|
||||
log.Printf("fs upload %s to %s: browser stream broke after %d of %d bytes: %v", p, agentID, n, r.ContentLength, err)
|
||||
}
|
||||
st.w.CloseWithError(err) // nil: the reader sees the end of the file
|
||||
}()
|
||||
|
||||
@@ -246,9 +250,10 @@ func (s *Server) handleFSDownload(w http.ResponseWriter, r *http.Request) {
|
||||
if st.size >= 0 {
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(st.size, 10))
|
||||
}
|
||||
if _, err := io.Copy(w, st.r); err != nil {
|
||||
if n, err := io.Copy(w, st.r); err != nil {
|
||||
// Cut the response off, so the browser does not take a part of
|
||||
// the file for all of it.
|
||||
log.Printf("fs download %s from %s: cut off after %d of %d bytes: %v", p, agentID, n, st.size, err)
|
||||
st.r.CloseWithError(err)
|
||||
panic(http.ErrAbortHandler)
|
||||
}
|
||||
@@ -310,9 +315,10 @@ func (s *Server) handleAgentFSStreamGet(w http.ResponseWriter, r *http.Request)
|
||||
if st.size >= 0 {
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(st.size, 10))
|
||||
}
|
||||
if _, err := io.Copy(w, st.r); err != nil {
|
||||
if n, err := io.Copy(w, st.r); err != nil {
|
||||
// The browser broke off: cut the response, so the agent does not
|
||||
// take a part of the file for all of it.
|
||||
log.Printf("fs upload to %s: cut off after %d of %d bytes: %v", a.ID, n, st.size, err)
|
||||
panic(http.ErrAbortHandler)
|
||||
}
|
||||
}
|
||||
@@ -338,9 +344,10 @@ func (s *Server) handleAgentFSStreamPost(w http.ResponseWriter, r *http.Request)
|
||||
http.Error(w, "gone", http.StatusGone)
|
||||
return
|
||||
}
|
||||
_, err = io.Copy(st.w, http.MaxBytesReader(w, r.Body, proto.FSFileCap))
|
||||
n, err := io.Copy(st.w, http.MaxBytesReader(w, r.Body, proto.FSFileCap))
|
||||
st.w.CloseWithError(err)
|
||||
if err != nil {
|
||||
log.Printf("fs download from %s: agent stream broke after %d of %d bytes: %v", a.ID, n, size, err)
|
||||
http.Error(w, "gone", http.StatusGone)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user