fix(wfctl): bound release asset downloads#860
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR bounds wfctl network downloads by attaching request-context deadlines to GitHub release asset and direct download HTTP requests, preventing indefinite hangs during wfctl plugin install and wfctl update.
Changes:
- Add request-context deadlines to
wfctl updaterelease asset downloads. - Add request-context deadlines to
wfctl plugin installrelease asset (API flow) and direct download paths. - Add a regression test ensuring the direct-download path uses a request context with a deadline.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cmd/wfctl/update.go |
Adds a timeout-bound request context to update-related downloads. |
cmd/wfctl/plugin_install.go |
Adds timeout-bound request contexts to plugin asset/direct download HTTP requests. |
cmd/wfctl/plugin_install_test.go |
Adds a regression test asserting direct downloads include a request deadline. |
Comment on lines
1164
to
1172
| // Step 2: download the asset binary. | ||
| assetURL := fmt.Sprintf("%s/repos/%s/%s/releases/assets/%d", //nolint:gosec // G107 | ||
| gitHubAPIBaseURL, | ||
| neturl.PathEscape(owner), | ||
| neturl.PathEscape(repo), | ||
| assetID, | ||
| ) | ||
| req2, err := http.NewRequest(http.MethodGet, assetURL, nil) | ||
| req2, err := http.NewRequestWithContext(ctx, http.MethodGet, assetURL, nil) | ||
| if err != nil { |
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
| if err := json.NewDecoder(resp.Body).Decode(&release); err != nil { | ||
| return nil, fmt.Errorf("decode GitHub release response: %w", err) | ||
| } | ||
| metadataCancel() |
Comment on lines
+137
to
+144
| got, err := downloadURL("https://example.com/plugin.tar.gz") | ||
| if err != nil { | ||
| t.Fatalf("downloadURL: %v", err) | ||
| } | ||
| if string(got) != "ok" { | ||
| t.Fatalf("downloadURL body = %q, want ok", got) | ||
| } | ||
| } |
Comment on lines
+68
to
+73
| div, exp := int64(unit), 0 | ||
| for next := n / unit; next >= unit && exp < 4; next /= unit { | ||
| div *= unit | ||
| exp++ | ||
| } | ||
| return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp]) |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
plugin installwfctl updatedownloadsVerification
GOWORK=off go test ./cmd/wfctl -run TestDownloadURL_DirectGetUsesBoundedRequestContext -count=1 -vfailed withrequest has no deadlineGOWORK=off go test ./cmd/wfctl -run TestDownloadURL_DirectGetUsesBoundedRequestContext -count=1 -vGOWORK=off go test ./cmd/wfctl -run 'TestDownloadURL|TestDownloadWithTimeout|TestRunUpdate' -count=1\n-GOWORK=off go test ./cmd/wfctl -count=1\n-git diff --check\n\n## Notes\nThis addresses the local hang observed while validatinggocodealone-dns: stalewfctl v0.74.1could sit indefinitely in a GitHub release download because plugin downloads usedhttp.DefaultClientwithout any timeout or request deadline.