From: pgjones <philip.graham.jones@googlemail.com>
Date: Mon, 27 Dec 2021 18:12:27 +0000
Subject: Bugfix only recycle a HTTP/1.1 connection if client is DONE

This will close rather than recycle a connection if the client is
still sending a body when the server is done recycling.

It is feasible for the server to wait for the client to finish sending
however this solution prevents a client slowly sending a body to the
server in an attempt to tie up server resources.

Origin: upstream, https://gitlab.com/pgjones/hypercorn/-/commit/13ef92a03fdcddd3f5b71b9b3450042a07e9556d
Bug: https://gitlab.com/pgjones/hypercorn/-/issues/219
---
 src/hypercorn/protocol/h11.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/hypercorn/protocol/h11.py b/src/hypercorn/protocol/h11.py
index 748a615..c8636bf 100755
--- a/src/hypercorn/protocol/h11.py
+++ b/src/hypercorn/protocol/h11.py
@@ -244,7 +244,11 @@ class H11Protocol:
 
     async def _maybe_recycle(self) -> None:
         await self._close_stream()
-        if not self.context.terminated and self.connection.our_state is h11.DONE:
+        if (
+            not self.context.terminated
+            and self.connection.our_state is h11.DONE
+            and self.connection.their_state is h11.DONE
+        ):
             try:
                 self.connection.start_next_cycle()
             except h11.LocalProtocolError:
