From 3b85b3bbad9a3104ac37b75f16ac210a6cd1a265 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Wed, 16 Feb 2022 18:03:05 +0200 Subject: [PATCH] Potential server crash if running Python 3.10 w/ Sanic 20.12 (#2400) --- sanic/__version__.py | 2 +- sanic/app.py | 13 +++++++++++++ sanic/server.py | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sanic/__version__.py b/sanic/__version__.py index 43f6a244..faa7ddb9 100644 --- a/sanic/__version__.py +++ b/sanic/__version__.py @@ -1 +1 @@ -__version__ = "20.12.5" +__version__ = "20.12.6" diff --git a/sanic/app.py b/sanic/app.py index 850e1fe3..0732bbd1 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -2,6 +2,7 @@ import logging import logging.config import os import re +import sys from asyncio import CancelledError, Protocol, ensure_future, get_event_loop from collections import defaultdict, deque @@ -65,6 +66,18 @@ class Sanic: if configure_logging: logging.config.dictConfig(log_config or LOGGING_CONFIG_DEFAULTS) + if sys.version_info >= (3, 10): + error_logger.error( + "Unsupported version of Python has been detected.\n\nPython " + f"version {sys.version} is not supported by this version of " + "Sanic. There is a security advisory that has been issued for " + "Sanic v20.12 while running Python 3.10+. You should either " + "use a supported version of Python (v3.6 - v3.9) or upgrade " + "Sanic to v21+.\n\nPlease see https://github.com/sanic-org/" + "sanic/security/advisories/GHSA-7p79-6x2v-5h88 for " + "more information.\n" + ) + self.name = name self.asgi = False self.router = router or Router(self) diff --git a/sanic/server.py b/sanic/server.py index 07b755ed..75c2bf79 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -169,7 +169,11 @@ class HttpProtocol(asyncio.Protocol): self.request_class = self.app.request_class or Request self.is_request_stream = self.app.is_request_stream self._is_stream_handler = False - self._not_paused = asyncio.Event(loop=deprecated_loop) + self._not_paused = ( + asyncio.Event() + if sys.version_info >= (3, 10) + else asyncio.Event(loop=deprecated_loop) + ) self._total_request_size = 0 self._request_timeout_handler = None self._response_timeout_handler = None