Skip to content

fix(tasks): DownloadFromFiles 把任务 ctx 串到 HTTP 请求#235

Merged
lovehunter9 merged 1 commit intomainfrom
cursor/fix-tasks-download-context
May 6, 2026
Merged

fix(tasks): DownloadFromFiles 把任务 ctx 串到 HTTP 请求#235
lovehunter9 merged 1 commit intomainfrom
cursor/fix-tasks-download-context

Conversation

@pengpeng
Copy link
Copy Markdown
Member

@pengpeng pengpeng commented May 5, 2026

概要

`pkg/tasks/task_paste_download.go` 的两次 `http.NewRequest`(一次拉文件树、一次拉单个文件)都没带任何 context。任务被 Pause / Cancel 时只有读循环里调用了 `t.isCancel()` 检测,但:

  • 慢的 dial、慢的服务端响应头阶段、连接被 hang 住 ⇒ 整个 HTTP roundtrip 仍然挂着
  • 任务的 ctx 已经 cancel,但传输层没有任何信号
  • 取消语义滞后,最坏情况下 worker goroutine 一直占着不放

改动

把两处 `http.NewRequest("GET", ...)` 改为 `http.NewRequestWithContext(t.ctx, "GET", ...)`。`net/http` Transport 看到 ctx cancel 会立刻终止 dial / 读 header / 读 body,cancellation 立刻生效。

验证方式

  • 手工:让 `filesServerIp` 上的端口接受连接但不返回数据(`nc -l`),触发 download;调用 `CancelTask`,确认 worker 立刻退出而不是停在 read header 上。
  • 正常下载流程不受影响。

Made with Cursor

Both http.NewRequest calls in DownloadFromFiles built request objects
with no context. Cancellation was only observed at the inner read
loop (via t.isCancel()), so a slow / stuck dial or response-header
phase could keep the HTTP roundtrip alive long after Pause/Cancel
fired and well past the task's intended lifetime.

Switch both to http.NewRequestWithContext(t.ctx, ...) so transport
cancellation kicks in immediately when the task is cancelled.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lovehunter9 lovehunter9 merged commit 379c591 into main May 6, 2026
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.

2 participants