Skip to content

Commit

Permalink
cdep: use ListContext instead of List to prevent/control context time…
Browse files Browse the repository at this point in the history
…out (#293)
  • Loading branch information
inancuvva committed Oct 20, 2021
1 parent 38b0a8f commit fb4a721
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/cdep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ You need an environment variable (`CUVVA_CODE_REPO`) with the location of where
Due to the tool doing a git fetch/pull/push, you need to have your SSH keys in your SSH Agent otherwise it won't know which to use to contact GitHub.

You can see what identities are already linked by going into your shell and entering `ssh-add -l`. If none are there, you'll need to add them by entering `ssh-add`.

### `context deadline exceeded`

This error originates from the third party package we are using to list the references on the remote repository.
We are currently hard coding the context timeout to 30 seconds and at the time of writing this duration seems to be
working fine. However, if it takes longer in future (which shouldn't really happen) you can bump it in the
[monorepo.go](tools/cdep/git/monorepo.go) file where `remote.ListContext` function is called.
6 changes: 5 additions & 1 deletion tools/cdep/git/monorepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package git
import (
"context"
"fmt"
"time"

"github.com/cuvva/cuvva-public-go/lib/cher"
"github.com/cuvva/cuvva-public-go/tools/cdep/paths"
Expand Down Expand Up @@ -35,7 +36,10 @@ func GetLatestCommitHash(ctx context.Context, branchName string) (string, error)
}
}

refs, err := remote.List(&gogit.ListOptions{})
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

refs, err := remote.ListContext(ctx, &gogit.ListOptions{})
if err != nil {
return "", err
}
Expand Down

0 comments on commit fb4a721

Please sign in to comment.