From 5b51b98801f2ecb17be11d17a2f8e26b1386e610 Mon Sep 17 00:00:00 2001 From: emranemran Date: Tue, 19 Mar 2024 13:22:21 -0700 Subject: [PATCH] uploader: reinit TeeReader on upload retry to reset pointer On an upload fail and retry, teeReader would not be reset and would point to the end of the buffer being uploaded. We need to reset teeReader to begin reading from the beginning of fileContents again. --- core/uploader.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/uploader.go b/core/uploader.go index df95b1a..8e0279c 100644 --- a/core/uploader.go +++ b/core/uploader.go @@ -73,11 +73,12 @@ func Upload(input io.Reader, outputURI *url.URL, waitBetweenWrites, writeTimeout return nil, fmt.Errorf("failed to read file") } - // To count how many bytes we are trying to read then write (upload) to s3 storage - teeReader := io.TeeReader(bytes.NewReader(fileContents), byteCounter) - var out *drivers.SaveDataOutput err = backoff.Retry(func() error { + // To count how many bytes we are trying to read then write (upload) to s3 storage + teeReader := io.TeeReader(bytes.NewReader(fileContents), byteCounter) + byteCounter.Count = 0 + out, err = session.SaveData(context.Background(), "", teeReader, fields, segmentWriteTimeout) if err != nil { glog.Errorf("failed upload attempt for %s (%d bytes): %v", outputURI.Redacted(), byteCounter.Count, err)