Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdep: use ListContext instead of List to prevent/control context timeout #293

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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