Skip to content

Connections hang in CLOSE-WAIT state #3182

Open
@Yerkwell

Description

@Yerkwell

If a post request with a large body gets error (413 or 404 or any other) as a response, the connection doesn't close, but hangs in CLOSE-WAIT state

Expected Behavior

After getting error connection is closed successfully

Current Behavior

Connection hangs in CLOSE-WAIT state with some bytes in Recv-Q

Possible Solution

As it only happens to requests with a large body, I guess there is something to do with the bytes that weren't read from a socket at the time the error happens. So we need to make sure these bytes are being read before closing the socket.

Steps to Reproduce (for bugs)

  1. Creating simple server
use actix_web::{App, HttpServer};

#[actix_web::main]
pub async fn main() {
    HttpServer::new(move || {
        App::new()
    })
        .bind("127.0.0.1:5556").unwrap()
        .run().await.unwrap();
}
  1. Making request with large body, that will end up with an error (404 in this case)
import requests
requests.post('http://127.0.0.1:5556/data', json={"data": "a"*1000000})
  1. Checking sockets - we can see the connections to our server in CLOSE-WAIT state with a lot of bytes in Recv-Q
$ ss -n4t | grep 5556
FIN-WAIT-2  0       0            127.0.0.1:59240        127.0.0.1:5556          
CLOSE-WAIT  787381  0            127.0.0.1:5556         127.0.0.1:59240

Context

We have an application that uses actix-web as http-api server. We've discovered that at some point it starts leaking the memory and connections. We've also found that another application is sending huge files to our app and keeps retrying as it gets 413 error. Future investigation showed that these things are connected and every 413 error leaves a connection in CLOSE-WAIT state. Later we managed to reproduce this problem with other errors (like 404 in the minimal example)

Your Environment

  • Rust Version: 1.70.0
  • Actix Web Version: 4.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-httpproject: actix-httpC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions