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
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.
There was a problem hiding this 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) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol TIL context.TODO()
internal/update/update.go
Outdated
| 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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