Skip to content

Commit

Permalink
feat: retry fetch when encounter stream error
Browse files Browse the repository at this point in the history
  • Loading branch information
pckhoi committed Jan 7, 2023
1 parent 5dcfa48 commit 8a896c0
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cmd/wrgl/fetch/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -331,6 +332,12 @@ func saveFetchedRefs(
return savedRefs, nil
}

var streamErrorRe = regexp.MustCompile(`.*stream error: stream ID \d+; INTERNAL_ERROR; received from peer$`)

func isStreamError(err error) bool {
return streamErrorRe.MatchString(err.Error())
}

func fetchObjects(
cmd *cobra.Command,
db objects.Store,
Expand Down Expand Up @@ -380,9 +387,16 @@ func Fetch(
if err != nil {
return fmt.Errorf("error fetching refs: %w", err)
}
fetchedCommits, err := fetchObjects(cmd, db, rs, client, advertised, depth, container)
if err != nil {
return fmt.Errorf("error fetching objects: %w", err)
var fetchedCommits [][]byte
for {
fetchedCommits, err = fetchObjects(cmd, db, rs, client, advertised, depth, container)
if err != nil {
if isStreamError(err) {
continue
}
return fmt.Errorf("error fetching objects: %w", err)
}
break
}
_, err = saveFetchedRefs(cmd, u, db, rs, remote, cr.URL, fetchedCommits, refs, dstRefs, maybeSaveTags, force)
return err
Expand Down

0 comments on commit 8a896c0

Please sign in to comment.