Skip to content

Commit

Permalink
Reducing memory consumption (#2831)
Browse files Browse the repository at this point in the history
Co-authored-by: n.feofanov <n.feofanov@visionlabs.ai>
Co-authored-by: Adam Hopkins <adam@amhopkins.com>
  • Loading branch information
3 people committed Nov 28, 2023
1 parent d1fc867 commit 1310684
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sanic/server/protocols/http_protocol.py
Expand Up @@ -109,6 +109,7 @@ class HttpProtocol(HttpProtocolMixin, SanicProtocol, metaclass=TouchUpMeta):
"_http",
"_exception",
"recv_buffer",
"_callback_check_timeouts",
)

def __init__(
Expand All @@ -135,6 +136,7 @@ def __init__(
if "requests_count" not in self.state:
self.state["requests_count"] = 0
self._exception = None
self._callback_check_timeouts = None

async def connection_task(self): # no cov
"""
Expand Down Expand Up @@ -214,7 +216,10 @@ def check_timeouts(self):
)
/ 2
)
self.loop.call_later(max(0.1, interval), self.check_timeouts)
_interval = max(0.1, interval)
self._callback_check_timeouts = self.loop.call_later(
_interval, self.check_timeouts
)
return
cancel_msg_args = ()
if sys.version_info >= (3, 9):
Expand All @@ -223,6 +228,19 @@ def check_timeouts(self):
except Exception:
error_logger.exception("protocol.check_timeouts")

def close(self, timeout: Optional[float] = None):
"""
Requires to prevent checking timeouts for closed connections
"""
if timeout is not None:
super().close(timeout=timeout)
return
if self._callback_check_timeouts:
self._callback_check_timeouts.cancel()
if self.transport:
self.transport.close()
self.abort()

async def send(self, data): # no cov
"""
Writes HTTP data with backpressure control.
Expand Down

0 comments on commit 1310684

Please sign in to comment.