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

Reducing memory consumption #2831

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sanic/server/protocols/base_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@
if self.transport:
self.transport.close()
if timeout is None:
timeout = self.app.config.GRACEFUL_SHUTDOWN_TIMEOUT
self.loop.call_later(timeout, self.abort)
self.abort()

Check warning on line 93 in sanic/server/protocols/base_protocol.py

View check run for this annotation

Codecov / codecov/patch

sanic/server/protocols/base_protocol.py#L93

Added line #L93 was not covered by tests
ahopkins marked this conversation as resolved.
Show resolved Hide resolved
else:
self.loop.call_later(timeout, self.abort)

Check warning on line 95 in sanic/server/protocols/base_protocol.py

View check run for this annotation

Codecov / codecov/patch

sanic/server/protocols/base_protocol.py#L95

Added line #L95 was not covered by tests

def abort(self):
"""
Expand Down
17 changes: 16 additions & 1 deletion sanic/server/protocols/http_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"_http",
"_exception",
"recv_buffer",
"_callback_check_timeouts",
)

def __init__(
Expand All @@ -135,6 +136,7 @@
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,7 @@
)
/ 2
)
self.loop.call_later(max(0.1, interval), self.check_timeouts)
self._callback_check_timeouts = self.loop.call_later(max(0.1, interval), self.check_timeouts)
return
cancel_msg_args = ()
if sys.version_info >= (3, 9):
Expand All @@ -223,6 +225,19 @@
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

Check warning on line 234 in sanic/server/protocols/http_protocol.py

View check run for this annotation

Codecov / codecov/patch

sanic/server/protocols/http_protocol.py#L233-L234

Added lines #L233 - L234 were not covered by tests
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
Loading