fix(download): 重试重置文件版标记;取消对挂起连接 500ms 内生效
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 48s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 48s
This commit is contained in:
1 parent
b12463cf0a
commit
39b2181b86
5 files changed
+33
-6
No files matched your search
@@ -363,16 +363,19 @@ async fn fetch_image_to(url: String, dst: String, base: Option<String>, req_id:
|
||||
if !req_key.is_empty() { if let Ok(mut map) = fetch_cancels().lock() { map.remove(&req_key); } }
|
||||
return Ok(serde_json::json!({ "ok": false, "error": "cancelled" }));
|
||||
}
|
||||
match resp.chunk().await {
|
||||
Ok(Some(chunk)) => {
|
||||
// 2026-12-04:每 500ms 醒一次检查取消标记 —— 服务端吊住不回包时也能及时取消/退出,
|
||||
// 不再等满 300s 总超时。
|
||||
match tokio::time::timeout(std::time::Duration::from_millis(500), resp.chunk()).await {
|
||||
Err(_elapsed) => continue,
|
||||
Ok(Ok(Some(chunk))) => {
|
||||
if let Err(e) = file.write_all(&chunk).await {
|
||||
let _ = tokio::fs::remove_file(&path).await;
|
||||
return Ok(serde_json::json!({ "ok": false, "error": e.to_string() }));
|
||||
}
|
||||
bytes += chunk.len() as u64;
|
||||
}
|
||||
Ok(None) => break,
|
||||
Err(e) => {
|
||||
Ok(Ok(None)) => break,
|
||||
Ok(Err(e)) => {
|
||||
let _ = tokio::fs::remove_file(&path).await;
|
||||
return Ok(serde_json::json!({ "ok": false, "error": e.to_string() }));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user