{"record":{"id":"d04f2935d71f0dd4","repo":"redis/redis-py","slug":"health-check-probes-must-be-greater-than-0","errorCode":null,"errorMessage":"health_check_probes must be greater than 0","messagePattern":"health_check_probes must be greater than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/multidb/healthcheck.py","lineNumber":357,"sourceCode":"\nclass HealthCheckPolicies(Enum):\n    HEALTHY_ALL = HealthyAllPolicy\n    HEALTHY_MAJORITY = HealthyMajorityPolicy\n    HEALTHY_ANY = HealthyAnyPolicy\n\n\nDEFAULT_HEALTH_CHECK_POLICY: HealthCheckPolicies = HealthCheckPolicies.HEALTHY_ALL\n\n\nclass AbstractHealthCheck(HealthCheck):\n    def __init__(\n        self,\n        health_check_probes: int = DEFAULT_HEALTH_CHECK_PROBES,\n        health_check_delay: float = DEFAULT_HEALTH_CHECK_DELAY,\n        health_check_timeout: float = DEFAULT_HEALTH_CHECK_TIMEOUT,\n    ):\n        if health_check_probes < 1:\n            raise ValueError(\"health_check_probes must be greater than 0\")\n        self._health_check_probes = health_check_probes\n        self._health_check_delay = health_check_delay\n        self._health_check_timeout = health_check_timeout\n\n    @property\n    def health_check_probes(self) -> int:\n        return self._health_check_probes\n\n    @property\n    def health_check_delay(self) -> float:\n        return self._health_check_delay\n\n    @property\n    def health_check_timeout(self) -> float:\n        return self._health_check_timeout\n\n    @abstractmethod\n    async def check_health(self, database, hc_client: AsyncRedisClientT) -> bool:","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/multidb/healthcheck.py#L339-L375","documentation":"Raised as ValueError by AbstractHealthCheck.__init__ (healthcheck.py:356-357) when the health_check_probes parameter is less than 1. A probe count of zero would make the health-check loops (HealthyAllPolicy/HealthyMajorityPolicy/HealthyAnyPolicy._execute) run zero iterations and report misleading health, so it is rejected at construction.","triggerScenarios":"Constructing PingHealthCheck(health_check_probes=0), LagAwareHealthCheck(health_check_probes=0), any AbstractHealthCheck subclass with probes=0, or setting MultiDbConfig.health_check_probes=0 (which is forwarded into the default PingHealthCheck). Negative values are equally rejected.","commonSituations":"Driving probes from an env var/config that defaulted to 0, computing probes from a formula that can hit zero (e.g. max(0, x)), misreading the parameter as a threshold rather than a count, or test fixtures that pass 0 to 'disable' probes.","solutions":["Set health_check_probes to at least 1 (the default DEFAULT_HEALTH_CHECK_PROBES is 3).","Validate the value before constructing the health check: probes = max(1, int(value)).","If you intended to disable health checks, do not set probes=0 — instead exclude the health check or reconfigure policy.","Audit config sources (env vars, YAML) for a probes/health_check_probes key that can resolve to 0."],"exampleFix":"// before\nhc = PingHealthCheck(health_check_probes=0)  # ValueError\n\n// after\nprobes = max(1, int(os.environ.get(\"HEALTH_CHECK_PROBES\", \"3\")))\nhc = PingHealthCheck(health_check_probes=probes)","handlingStrategy":"validation","validationCode":"def valid_probe_count(n) -> bool:\n    return isinstance(n, int) and n >= 1\n\nprobes = int(os.environ.get(\"HEALTH_CHECK_PROBES\", \"3\"))\nif not valid_probe_count(probes):\n    raise ValueError(f\"health_check_probes must be >= 1, got {probes}\")\n\nhc = PingHealthCheck(health_check_probes=probes)","typeGuard":"def is_positive_int(n) -> bool:\n    return isinstance(n, int) and not isinstance(n, bool) and n >= 1","tryCatchPattern":"try:\n    hc = PingHealthCheck(health_check_probes=probes)\nexcept ValueError as e:\n    if \"health_check_probes must be greater than 0\" in str(e):\n        probes = max(1, int(probes) if probes else 3)\n        hc = PingHealthCheck(health_check_probes=probes)\n    else:\n        raise","preventionTips":["Clamp externally sourced probe counts: probes = max(1, int(value)).","Audit env vars / YAML for health_check_probes keys that can resolve to 0 or negative.","Do not overload health_check_probes as a 'disable' switch — exclude the health check instead.","Add a config schema test asserting probes >= 1 for every health check."],"tags":["multidb","health-check","validation","config"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}