update sanic/http protocols close
methods
This commit is contained in:
parent
a5a9658896
commit
6e375850c1
|
@ -90,8 +90,9 @@ class SanicProtocol(asyncio.Protocol):
|
|||
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()
|
||||
else:
|
||||
self.loop.call_later(timeout, self.abort)
|
||||
|
||||
def abort(self):
|
||||
"""
|
||||
|
|
|
@ -109,6 +109,7 @@ class HttpProtocol(HttpProtocolMixin, SanicProtocol, metaclass=TouchUpMeta):
|
|||
"_http",
|
||||
"_exception",
|
||||
"recv_buffer",
|
||||
"_callback_check_timeouts",
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
@ -135,6 +136,7 @@ class HttpProtocol(HttpProtocolMixin, SanicProtocol, metaclass=TouchUpMeta):
|
|||
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
|
||||
"""
|
||||
|
@ -214,7 +216,7 @@ class HttpProtocol(HttpProtocolMixin, SanicProtocol, metaclass=TouchUpMeta):
|
|||
)
|
||||
/ 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):
|
||||
|
@ -223,6 +225,19 @@ class HttpProtocol(HttpProtocolMixin, SanicProtocol, metaclass=TouchUpMeta):
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user