]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: limit number of allowed workers
authorVasek Sraier <git@vakabus.cz>
Fri, 11 Mar 2022 11:49:14 +0000 (12:49 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:54 +0000 (16:17 +0200)
manager/knot_resolver_manager/datamodel/server_schema.py
manager/knot_resolver_manager/datamodel/types/base_types.py

index 1c623413bd9dc7837d7a6a3ac0ace6fb4c1cb4c2..0bdb9f6e130bc3c10d783a07a2137c38617a93aa 100644 (file)
@@ -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")
index 7dc203a7e9a4308416da882eb0721f6f9b28c836..954b94a9a06e99112041693cafed575fd3ceee03 100644 (file)
@@ -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(