{"id":"a6e9eab9252c995c","repo":"pika/pika","slug":"socket-timeout-must-be-0-but-got-value-r","errorCode":null,"errorMessage":"socket_timeout must be > 0, but got {value!r}","messagePattern":"socket_timeout must be > 0, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pika/connection.py","lineNumber":443,"sourceCode":"        :returns: socket connect timeout in seconds. Defaults to\n            `DEFAULT_SOCKET_TIMEOUT`. The value None disables this timeout.\n\n        \"\"\"\n        return self._socket_timeout\n\n    @socket_timeout.setter\n    def socket_timeout(self, value: float | None) -> None:\n        \"\"\"\n        :param value: positive socket connect timeout in\n            seconds. None to disable this timeout.\n\n        \"\"\"\n        if value is not None:\n            if not isinstance(value, numbers.Real):\n                raise TypeError('socket_timeout must be a float or int, '\n                                f'but got {value!r}')\n            if value <= 0:\n                raise ValueError(\n                    f'socket_timeout must be > 0, but got {value!r}')\n            value = float(value)\n\n        self._socket_timeout = value\n\n    @property\n    def stack_timeout(self) -> float | None:\n        \"\"\"\n        :returns: full protocol stack TCP/[SSL]/AMQP bring-up timeout in\n            seconds. Defaults to `DEFAULT_STACK_TIMEOUT`. The value None\n            disables this timeout.\n\n        \"\"\"\n        return self._stack_timeout\n\n    @stack_timeout.setter\n    def stack_timeout(self, value: float | None) -> None:\n        \"\"\"","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/pika/pika/blob/295ad9e5795061d759b694ab1fcb33cd381d8c49/pika/connection.py#L425-L461","documentation":"Raised by the `socket_timeout` setter (pika/connection.py:443) when a numeric value is <= 0. A non-positive connect timeout is meaningless (it would make every connect instantly fail), so pika rejects it after the type check. None is the documented way to disable the timeout, not 0.","triggerScenarios":"`params.socket_timeout = 0`, `params.socket_timeout = -1`, or `ConnectionParameters(socket_timeout=0.0)`.","commonSituations":"Assuming 0 means 'no timeout' (common convention in other libraries), computing a timeout that underflows to 0, or inheriting a default from another tool that uses 0 as 'infinite'.","solutions":["Pass `None` to disable the timeout, not 0.","Pick a positive value matched to your network (e.g. 5-10 seconds).","Clamp computed timeouts: `params.socket_timeout = timeout if timeout > 0 else None`.","Document in your config schema that 0 is invalid for this field."],"exampleFix":"# before\nparams.socket_timeout = 0  # intended 'no timeout'\n# after\nparams.socket_timeout = None","handlingStrategy":"validation","validationCode":"def parse_socket_timeout(v):\n    if v is None:\n        return None\n    f = float(v)\n    if f <= 0:\n        raise ValueError(f'socket_timeout must be > 0, got {f}')\n    return f\nparams.socket_timeout = parse_socket_timeout(raw)","typeGuard":"import numbers\ndef is_positive_or_none(v) -> bool:\n    return v is None or (isinstance(v, numbers.Real) and v > 0)","tryCatchPattern":"try:\n    params.socket_timeout = raw\nexcept ValueError:\n    params.socket_timeout = None  # disable instead","preventionTips":["Reserve 0/None semantics: None disables, 0 is invalid.","Clamp computed timeouts to a positive minimum.","Document in your config schema that 0 is rejected."],"tags":["socket-timeout","value-validation","configuration","connection-parameters"],"analyzedSha":"295ad9e5795061d759b694ab1fcb33cd381d8c49","analyzedAt":"2026-08-04T20:47:41.389Z","schemaVersion":2}