Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connections hang in CLOSE-WAIT state #3182

Open
Yerkwell opened this issue Nov 2, 2023 · 0 comments
Open

Connections hang in CLOSE-WAIT state #3182

Yerkwell opened this issue Nov 2, 2023 · 0 comments
Labels
A-http project: actix-http C-bug Category: bug

Comments

@Yerkwell
Copy link

Yerkwell commented Nov 2, 2023

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
@robjtede robjtede added C-bug Category: bug A-http project: actix-http labels Nov 2, 2023
@robjtede robjtede added this to the actix-web v4.4 milestone Nov 2, 2023
@robjtede robjtede removed this from the actix-web v4.4 milestone Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-http project: actix-http C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants