From: Vasek Sraier Date: Fri, 11 Mar 2022 11:49:14 +0000 (+0100) Subject: manager: limit number of allowed workers X-Git-Tag: v6.0.0a1~40^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f19e922e16e5440e64fd7cec5b7f4488c9e11842;p=thirdparty%2Fknot-resolver.git manager: limit number of allowed workers --- diff --git a/manager/knot_resolver_manager/datamodel/server_schema.py b/manager/knot_resolver_manager/datamodel/server_schema.py index 1c623413b..0bdb9f6e1 100644 --- a/manager/knot_resolver_manager/datamodel/server_schema.py +++ b/manager/knot_resolver_manager/datamodel/server_schema.py @@ -147,5 +147,13 @@ class ServerSchema(SchemaNode): return obj.workers def _validate(self) -> None: + try: + cpu_count = _cpu_count() + if int(self.workers) > 10 * cpu_count: + raise ValueError("refusing to run with more then instances 10 instances per cpu core") + except DataException: + # sometimes, we won't be able to get information about the cpu count + pass + if self.watchdog and self.backend not in ["auto", "systemd"]: raise ValueError("'watchdog' can only be configured for 'systemd' backend") diff --git a/manager/knot_resolver_manager/datamodel/types/base_types.py b/manager/knot_resolver_manager/datamodel/types/base_types.py index 7dc203a7e..954b94a9a 100644 --- a/manager/knot_resolver_manager/datamodel/types/base_types.py +++ b/manager/knot_resolver_manager/datamodel/types/base_types.py @@ -75,13 +75,9 @@ class IntRangeBase(IntBase): super().__init__(source_value) if isinstance(source_value, int) and not isinstance(source_value, bool): if hasattr(self, "_min") and (source_value < self._min): - raise SchemaException( - f"value {source_value} is lower than the minimum {self._min}.", object_path - ) + raise SchemaException(f"value {source_value} is lower than the minimum {self._min}.", object_path) if hasattr(self, "_max") and (source_value > self._max): - raise SchemaException( - f"value {source_value} is higher than the maximum {self._max}", object_path - ) + raise SchemaException(f"value {source_value} is higher than the maximum {self._max}", object_path) self._value = source_value else: raise SchemaException(