actix / actix-web

Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust.
https://actix.rs
Apache License 2.0
20.74k stars 1.63k forks source link

Pending multipart request with angular rxjs #3220

Open jonatansalemes opened 6 months ago

jonatansalemes commented 6 months ago

i`m facing a very strange issue when i have multipart endpoints in actix using angular app (rxjs client):

actix endpoint

#[post("/mt")]
pub async fn service(payload: Multipart) -> Result<impl Responder, Error> {
    if true {
        let bad_request =
            HttpResponse::BadRequest().json(BadRequestError(BadRequestErrorResponse {
                message: "You don't have enough balance".to_string(),
            }));
        return Ok(bad_request);
    }

    Ok(HttpResponse::Ok().json("ss"))
}

angular http client request

    createNew(f1: File, f2: File) {
        const apiUrl = this.appConfig.apiUrl;
        const formData = new FormData();
        formData.set('f1', f1, f1.name);
        formData.set('f2', f2, f2.name);
        return this.httpClient
            .post<CreateNewSwapResponse>(`${apiUrl}/mt`, formData);
    }

after first bad request, the next request get in pending status forever in network tab.

i have switched to spring boot endpoint, that works nice without pending behaviour, to check headers difference. So spring after bad request send header

[only header, not closing server socket] Connection: close

actix does not sent nothing, after explore actix source code

image

i have, just for test, force connection close on encoder.rs even is keep alive was sent by client and stop hanging pending request in client after that. There is some way to add feature like force_close_header only ? because i have tryied force_close but this close socket generating error. Another idea maybe is respect if add_header(("Connection", "close")) was added instead use connection type to write connection header. Some idea ? i can write a pull request if need it.

kvzn commented 6 months ago

Got the same issue, thank you for your fixing, hope the PR be merged asap.