Disallow update checker delaying the gh process#6978
Merged
Conversation
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.
vilmibm
approved these changes
Feb 6, 2023
| ) | ||
|
|
||
| rel, err := CheckForUpdate(client, tempFilePath(), "OWNER/REPO", s.CurrentVersion) | ||
| rel, err := CheckForUpdate(context.TODO(), httpClient, tempFilePath(), "OWNER/REPO", s.CurrentVersion) |
samcoe
reviewed
Feb 6, 2023
internal/update/update.go
Outdated
| } | ||
|
|
||
| var latestRelease ReleaseInfo | ||
| if err := restClient.DoWithContext(ctx, "GET", fmt.Sprintf("repos/%s/releases/latest", repo), nil, &latestRelease); err != nil { |
Contributor
There was a problem hiding this comment.
@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?
Contributor
Author
There was a problem hiding this comment.
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
samcoe
reviewed
Feb 6, 2023
cmd/gh/main.go
Outdated
| updateMessageChan := make(chan *update.ReleaseInfo) | ||
| go func() { | ||
| rel, _ := checkForUpdate(buildVersion) | ||
| rel, err := checkForUpdate(updateCtx, buildVersion) |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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