chore: log where and after how many bytes a file transfer breaks

This commit is contained in:
redtea committed 2026-10-14 18:49:07 +03:00
1 parent 19f8b5291e
commit 438b20dae0
2 files changed
+17 -4

No files matched your search

+6
View File
@@ -5,11 +5,13 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
"path/filepath"
"strconv"
"syscall"
"time"
"github.com/x-grk/longpolling-remote-access/internal/proto"
)
@@ -62,6 +64,7 @@ func (a *Agent) doFSUpload(ctx context.Context, env proto.TaskEnvelope) proto.Ta
}
n, err := io.Copy(tmp, io.LimitReader(resp.Body, proto.FSFileCap+1))
if err != nil {
log.Printf("fs receive %s: broke after %d of %d bytes: %v", args.Path, n, args.Size, err)
return proto.TaskResult{Error: "загрузка прервана: " + err.Error()}
}
if n > proto.FSFileCap {
@@ -123,13 +126,16 @@ func (a *Agent) doFSGet(ctx context.Context, env proto.TaskEnvelope) proto.TaskR
req.ContentLength = info.Size()
req.Header.Set("X-Size", strconv.FormatInt(info.Size(), 10))
a.authHeaders(req)
start := time.Now()
resp, err := a.stream.Do(req)
if err != nil {
log.Printf("fs send %s (%d bytes): failed after %s: %v", args.Path, info.Size(), time.Since(start).Round(time.Millisecond), err)
return proto.TaskResult{Error: err.Error()}
}
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
log.Printf("fs send %s (%d bytes): server answered %d after %s", args.Path, info.Size(), resp.StatusCode, time.Since(start).Round(time.Millisecond))
return proto.TaskResult{Error: "браузер не дочитал файл"}
}
data, _ := json.Marshal(map[string]any{"path": args.Path, "size": info.Size()})