-
-
Notifications
You must be signed in to change notification settings - Fork 755
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
Fix ensure http connection is closed #1332
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pacoyang!
I've confirmed that this PR solves our issues: memory leak and CLOSE_WAIT. The logic here also makes sense to me, and I've specially liked the usage of the MUST_CLOSE
state. 👍
That being said... I still think uvicorn
should revert #869 . It's been almost a year and no one took the initiative to continue the work into trio compatibility.
In any case, I'll wait 10 days. If no other member gets involved on this PR, I'll approve, merge and release.
elif event_type is h11.ConnectionClosed: | ||
break | ||
if self.conn.our_state is h11.MUST_CLOSE and not self.transport.is_closing(): | ||
self.transport.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine 👍
if data == b"" and not self.transport.is_closing(): | ||
self.transport.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine 👍
@tomchristie @abersheeran @euri10 @florimondmanca friendly ping if someone wants to check this as well |
@Kludex Sure, I just want to solve this issue as soon as possible, any way is acceptable. I love Using a streams handler can do more things like move the keep-alive timeout task out of the protocol, so we don't need to write multiple times in the protocol implementation. The keep-alive timeout task trigger still has issue, when a TCP connection is established and the client does not send any bytes, the server does not close this connection when keep-alive timeout. It can be reproduced by |
Just stumbled upon this when running on fly.io with TCP health checks. Luckily I could switch over to HTTP checks to get around this, but following this to be sure it's resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @pacoyang !
…closed (encode#1332)" (encode#1354) This reverts commit fc6e056.
* Revert "fix: move all data handle to protocol & ensure connection is closed (encode#1332)" This reverts commit fc6e056. * Revert stream interface
this is required for it to stay working with the AWS ELB encode/uvicorn#1199 encode/uvicorn#1332 but we're still waiting for `fastapi[all]` to use the newer uvicorn: fastapi/fastapi#4680
Ref Issues: #1199 #1226
Ref PRs: #1192 #1244 #1307
Description
As #869 (released in 0.14.0) is missing handle the scenario of
b""
, it is possible to make the HTTP connection not close correctly.Here is the memory usage plot with the current main branch, running a single
tcping
process for 5 minutes.The memory usage is increasing, and the
netstat
shows manyCLOSE_WAIT
connections.I read the code in #869 , I have found two issues:
b""
to protocol.data_received too. It is up to the protocol to determine if the connection should be closed or not._buffer
seems not a good way. In some scenarios, the client will initially send empty TCP pings, then_buffer
will receiveb""
, determine if the connections should be closed or not through the_buffer
data is confusing (refs from the read function).Here is current PR code running a single
tcping
process for 5 minutes in the same testing environment:Test codes: