diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index afaa5daf..9e910026 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -831,6 +831,14 @@ The maximum number of parallel connections. Set to `0` to disable the limit. Default: `8` +##### delay_on_error + +_(>= 3.7.0)_ + +Base delay in case of error response (seconds) + +Default: `0.01` + ##### max_content_length The maximum size of the request body. (bytes) diff --git a/config b/config index 4b157fc7..86363049 100644 --- a/config +++ b/config @@ -21,6 +21,9 @@ # Max parallel connections #max_connections = 8 +# Base delay in case of error response (seconds) +#delay_on_error = 0.01 + # Max size of request body (bytes), default: 100 Mbyte # In case of using a reverse proxy in front of check also there related option #max_content_length = 100000000 diff --git a/radicale/app/__init__.py b/radicale/app/__init__.py index 0ecdd7e9..875d876b 100644 --- a/radicale/app/__init__.py +++ b/radicale/app/__init__.py @@ -72,6 +72,7 @@ class Application(ApplicationPartDelete, ApplicationPartHead, _mask_passwords: bool _auth_delay: float + _delay_on_error: float _internal_server: bool _max_content_length: int _max_resource_size: int @@ -97,6 +98,8 @@ class Application(ApplicationPartDelete, ApplicationPartHead, """ super().__init__(configuration) self._mask_passwords = configuration.get("logging", "mask_passwords") + self._delay_on_error = configuration.get("server", "delay_on_error") + logger.info("delay_on_error set to: %.3f seconds", self._delay_on_error) self._max_content_length = configuration.get("server", "max_content_length") self._max_resource_size = configuration.get("server", "max_resource_size") logger.info("max_content_length set to: %d bytes (%sbytes)", self._max_content_length, utils.format_unit(self._max_content_length, binary=True)) @@ -304,6 +307,14 @@ class Application(ApplicationPartDelete, ApplicationPartHead, flags_text = " (" + " ".join(flags) + ")" else: flags_text = "" + # delay on error + if status >= 400: + random_delay = self._delay_on_error * (1 + random.random()) + if status >= 500: + random_delay = 2 * random_delay + if logger.isEnabledFor(logging.DEBUG): + logger.debug("Response delay triggered by result code: %d -> %0.3f seconds", status, random_delay) + time.sleep(random_delay) if answer is not None: logger.info("%s response status for %r%s in %.3f seconds %s %s bytes%s: %s", request_method, unsafe_path, depthinfo, diff --git a/radicale/config.py b/radicale/config.py index bf04d7f4..76e4fdbd 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -171,6 +171,10 @@ DEFAULT_CONFIG_SCHEMA: types.CONFIG_SCHEMA = OrderedDict([ "value": "100000000", "help": "maximum size of request body in bytes (default: 100 Mbyte)", "type": positive_int}), + ("delay_on_error", { + "value": "0.01", + "help": "base delay in case of error response (seconds)", + "type": positive_float}), ("max_resource_size", { "value": "10000000", "help": "maximum size of resource (default: 10 Mbyte)",