{"record":{"id":"c7ae0fb19f91ddb0","repo":"SeleniumHQ/selenium","slug":"timeout-must-be-a-positive-number","errorCode":null,"errorMessage":"timeout must be a positive number","messagePattern":"timeout must be a positive number","errorType":"validation","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/websocket_connection.py","lineNumber":86,"sourceCode":"                    for pf in dataclasses.fields(value):\n                        pv = getattr(value, pf.name)\n                        if pv is not None:\n                            result[_snake_to_camel(pf.name)] = self._convert(pv)\n                else:\n                    result[camel_key] = self._convert(value)\n            return result\n        return super().default(o)\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass WebSocketConnection:\n    _max_log_message_size = 9999\n\n    def __init__(self, url, timeout, interval):\n        if not isinstance(timeout, (int, float)) or timeout < 0:\n            raise WebDriverException(\"timeout must be a positive number\")\n        if not isinstance(interval, (int, float)) or timeout < 0:\n            raise WebDriverException(\"interval must be a positive number\")\n\n        self.url = url\n        self.response_wait_timeout = timeout\n        self.response_wait_interval = interval\n\n        self.callbacks = {}\n        self.session_id = None\n        self._id = 0\n        self._id_lock = threading.Lock()\n        self._messages = {}\n        self._started = False\n\n        self._start_ws()\n        self._wait_until(lambda: self._started)\n\n    def close(self):","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/websocket_connection.py#L68-L104","documentation":"Raised by WebSocketConnection.__init__ when the timeout argument is not an int/float or is negative. The constructor builds the BiDi/CDP websocket channel and needs a valid wait timeout. Note a real bug on the next line: the interval validation checks `timeout < 0` again instead of `interval < 0`, so a negative interval is not caught by its own guard (it can still slip through), and the message says 'positive' while the code actually allows 0.","triggerScenarios":"Constructing WebSocketConnection(url, timeout, interval) with timeout=None, a string, or a negative number. In practice this is triggered indirectly via driver.script/network (which pass command_executor.client_config.websocket_timeout) when that config value is misconfigured.","commonSituations":"A custom client_config with websocket_timeout set to None or a negative value, or a subclass that overrides the config. The direct constructor is rarely called by users.","solutions":["Ensure client_config.websocket_timeout and websocket_interval are positive numbers (e.g. 60 and 0.1).","If constructing WebSocketConnection directly, pass numeric non-negative values for timeout and interval.","File/fix the upstream bug: the interval guard should check `interval < 0`, not `timeout < 0`."],"exampleFix":"# before\nconn = WebSocketConnection(url, timeout=-1, interval=0.1)  # raises\n\n# after\nconn = WebSocketConnection(url, timeout=60, interval=0.1)","handlingStrategy":"validation","validationCode":"if not isinstance(timeout, (int, float)) or timeout < 0:\n    raise ValueError('timeout must be a non-negative number')\nif not isinstance(interval, (int, float)) or interval < 0:\n    raise ValueError('interval must be a non-negative number')\nconn = WebSocketConnection(url, timeout, interval)","typeGuard":"def is_valid_ws_timeout(v) -> bool:\n    return isinstance(v, (int, float)) and v >= 0","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    conn = WebSocketConnection(url, timeout, interval)\nexcept WebDriverException:\n    conn = WebSocketConnection(url, 60, 0.1)  # safe defaults","preventionTips":["Keep client_config.websocket_timeout / websocket_interval as positive numbers.","Validate numeric config values at construction.","Note the upstream bug: the interval guard checks `timeout` not `interval`; validate interval yourself."],"tags":["websocket","bidi","configuration","argument-validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}