Skip to content

Commit

Permalink
client: seek to start of buffer on error
Browse files Browse the repository at this point in the history
attempt to move the buffer back when we plan on re-writing the file
  • Loading branch information
johnsonj committed Oct 25, 2017
1 parent 03c81f5 commit 7a2a1ad
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func (client *GCSBlobstore) Put(src io.ReadSeeker, dest string) error {
return err
}

pos, err := src.Seek(0, io.SeekCurrent)
if err != nil {
return fmt.Errorf("finding buffer position: %v", err)
}

var errs []error
for i := 0; i < retryAttempts; i++ {
err := client.putOnce(src, dest)
Expand All @@ -118,6 +123,10 @@ func (client *GCSBlobstore) Put(src io.ReadSeeker, dest string) error {

errs = append(errs, err)
log.Printf("upload failed for %s, attempt %d/%d: %v\n", dest, i+1, retryAttempts, err)

if _, err := src.Seek(pos, io.SeekStart); err != nil {
return fmt.Errorf("restting buffer position after failed upload: %v", err)
}
}

return fmt.Errorf("upload failed for %s after %d attempts: %v", dest, retryAttempts, errs)
Expand Down

0 comments on commit 7a2a1ad

Please sign in to comment.