actix / actix/actix-web

Infinite Request Pending on Uploading Large Multipart Files

未关闭
#3,152 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Rust
星标
24.8k
派生
1.9k
平均合并
23 小时 10 分钟
30 天内合并 PR
26

描述

**Expected Behavior**
When uploading a file larger than the allowed multipart file size limit (50 MB in this case), the server should promptly respond with an appropriate error message, such as "payload reached size limit", and the request should not be left pending indefinitely.

**Current Behavior**
When a file of size around 51 MB is uploaded, the server responds correctly with "payload reached size limit". However, if a much larger file, say around 200 MB, is uploaded, the request remains pending indefinitely, although a "Multipart error" is logged in the console.

```
[dependencies]
actix-web = "4.4"
actix-multipart = "0.6.1"
```

```rs
#[derive(Debug, MultipartForm)]
struct UploadForm {
owner: Text,

#[multipart(rename = "file")]
files: Vec,
}

#[post("/upload")]
async fn upload(MultipartForm(form): MultipartForm) -> Result {
let owner: &str = &form.creator;

log::info!("Uploading {} file(s) to {}", file_count, owner);

for f in form.files {
let path = format!("{}/{}", UPLOAD_DIR, f.file_name.unwrap());
log::info!("Saving to {path}");
f.file.persist(path).unwrap();
}

Ok(HttpResponse::Ok().body("File uploaded."))
}

#[get("/")]
async fn index() -> Result {
let html = r#"
Upload Test




Submit


"#;

Ok(HttpResponse::Ok().body(html))
}

fn handle_multipart_error(err: MultipartError, req: &HttpRequest) -> Error {
log::error!("Multipart error: {}", err);

return Error::from(err);
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

log::info!("Starting HTTP server at {}:{}", HOST, PORT);

HttpServer::new(move || {
App::new()
.wrap(Logger::default())
.app_data(
MultipartFormConfig::default()
.total_limit(50 * 1024 * 1024) // 50 MB
.memory_limit(10 * 1024 * 1024) // 10 MB
.error_handler(handle_multipart_error),
)
.service(index)
.service(upload)
})
.workers(2)
.bind((HOST, PORT))?
.run()
.await
}

```

贡献指南

打开贡献指南

调研方向

Start by reproducing the large-upload case with the shown upload entry point and MultipartFormConfig limits, then inspect multipart error handling around handle_multipart_error. Compare the 51 MB and 200 MB behaviors and trace why the request remains pending after the logged Multipart error. Done means oversized multipart uploads return an error promptly instead of remaining pending.

由索引模型根据 Issue 内容生成。

评估

技术栈
rust
领域
api, backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。