fix(tasks): DownloadFromFiles 在 Do 失败时不再对 nil resp.Body 调 Close#234
Open
fix(tasks): DownloadFromFiles 在 Do 失败时不再对 nil resp.Body 调 Close#234
Conversation
When streamHTTPClient.Do(downloadReq) returns an error, the response is typically nil and the immediate downloadResp.Body.Close() inside the error branch panics with nil pointer dereference. The bug is reachable any time the download endpoint refuses or times out. Just break out of the loop; there is nothing to close on a Do error. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
概要
`pkg/tasks/task_paste_download.go` 在下载循环里:
```go
downloadResp, err = streamHTTPClient.Do(downloadReq)
if err != nil {
klog.Errorf("[Task] Id: %s, download failed, url: %s, error: %v", t.id, downloadUrl, err)
downloadResp.Body.Close() // <-- 这里
break
}
```
按 Go 的 `net/http` 文档,当 `Do` 返回非 nil error 时,Response 通常是 nil。这一行 `downloadResp.Body.Close()` 会触发 nil 指针解引用,把任务 worker goroutine 直接 panic 掉——只要下载端点拒绝或超时就触发。
改动
去掉这次 `Body.Close()`:Do 出错时本来就没有可关闭的 body。
验证方式
Made with Cursor