From b794ab707434709a7d2b6b7371e2783fff2586a7 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..8390dc4 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.Reset() + 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)