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

Disallow update checker delaying the gh process #6978

Merged
merged 2 commits into from Feb 7, 2023
Merged

Conversation

mislav
Copy link
Member

@mislav mislav commented Feb 6, 2023

This ensures that checking for newer versions of gh happens in the background of the main operation that the user requested, and that when that operation is completed, the gh process should immediately exit without being delayed by the update checker goroutine.

Fixes #6867

This ensures that checking for newer versions of gh happens in the background of the main operation that the user requested, and that when that operation is completed, the gh process should immediately exit without being delayed by the update checker goroutine.
@mislav mislav requested a review from a team as a code owner February 6, 2023 19:01
@mislav mislav requested review from vilmibm and removed request for a team February 6, 2023 19:01
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI Feb 6, 2023
Copy link
Member

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@@ -85,7 +84,7 @@ func TestCheckForUpdate(t *testing.T) {
}`, s.LatestVersion, s.LatestURL)),
)

rel, err := CheckForUpdate(client, tempFilePath(), "OWNER/REPO", s.CurrentVersion)
rel, err := CheckForUpdate(context.TODO(), httpClient, tempFilePath(), "OWNER/REPO", s.CurrentVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol TIL context.TODO()

The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 Feb 6, 2023
if err != nil {
return nil, err
}

var latestRelease ReleaseInfo
if err := restClient.DoWithContext(ctx, "GET", fmt.Sprintf("repos/%s/releases/latest", repo), nil, &latestRelease); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mislav Do you think it makes sense to introduce a new function RESTWithContext similar to QueryWithContext to the api.Client so that we don't need to go through the steps of creating a gh.RESTClient?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with switching to gh.RESTClient; I'd rather not be extending api.Client with any new functionality and instead deprecate api.Client altogether

cmd/gh/main.go Outdated
updateMessageChan := make(chan *update.ReleaseInfo)
go func() {
rel, _ := checkForUpdate(buildVersion)
rel, err := checkForUpdate(updateCtx, buildVersion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With rearranging this code so cmdFactory is created above the checkForUpdate we can now inject the api client from the factory if we wanted to.

@mislav mislav enabled auto-merge (squash) February 7, 2023 19:43
@mislav mislav merged commit 626c639 into trunk Feb 7, 2023
10 checks passed
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 Feb 7, 2023
@mislav mislav deleted the update-checker-cancel branch February 7, 2023 19:52
@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

gh <anything> hangs after completion for ~30 seconds
3 participants