Skip to content

Conversation

@mislav
Copy link
Contributor

@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
Copy link
Contributor

@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

)

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

Choose a reason for hiding this comment

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

lol TIL context.TODO()

}

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

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
Contributor 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
Contributor

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
@mislav mislav deleted the update-checker-cancel branch February 7, 2023 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh <anything> hangs after completion for ~30 seconds

4 participants