actix-web: Connection not closed correctly

Connection are not closed correctly by default What I means is: if you do a “netstat -ano” you will see connection list growing and growing. Not all old connection get closed.

Tested with StaticFile handler ( HTTP2 or not ) on a website with ~20k+ daily users

With the default config -> Not closed correctly With .keep_alive(None) -> Not closed correctly With .keep_alive(server::KeepAlive::Timeout(5)) -> All connections are closed correctly

Initially detected in this ticket #426 but it was not the main issue

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 116 (63 by maintainers)

Most upvoted comments

I wonder why this bug has no attention for so long time (since Nov 24 2018). If server fails due memory leaks - how you run your web sites on it?

@fafhrd91, @DoumanAsh Hi! Has this issue actually been properly solved? I’ve been using 1.x version of actix-web for months, had to restart my app every now and then (sometimes after minutes, sometimes after days) since there are a lot of ESTABLISHED connections left there hanging, eventually causing too many open files error. I’m using my server with keep-alive disabled, the rest of the settings are the defaults. I have since tried to upgrade to 2.0.0 to see if it solves the problem, but it’s the same thing.

The service itself gets around 500-1000 requests per second in production currently.

@legokichi should be fixed in master

@neowutran could you test master again?

@DoumanAsh i’ll handle this

Thanks! It is strange because we should set shutdown flag on expiration of timer. I’ll try to check code there again when I’ll have time

@legokichi I think in this case it is supposed to be set in either request or response already. Though I need to re-check code to be sure

UPD: Settings are used here to determine whether we should start keep-alive timer itself https://github.com/actix/actix-web/blob/cfd9a56ff74dd6cb6ad38b6a67b40ed1763d6071/src/server/h1.rs#L93-L123

Though looking at how we set headers I wonder if we’re actually doing it wrong as on HTTP1.1 we should set keep-alive to connection when keep-alive is on, and Close otherwise, while for HTTP1.0 it is always by default should be close and we don’t even need to set it

@fafhrd91 What do you think?

UPD: though maybe we need to set keep-alive for HTTP1.0, but I think we should set it for HTTP1.1 too