{"record":{"id":"31e2062a7257df20","repo":"SeleniumHQ/selenium","slug":"can-not-connect-to-the-service-self-path","errorCode":null,"errorMessage":"Can not connect to the Service {self._path}","messagePattern":"Can not connect to the Service (.+?)","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/service.py","lineNumber":120,"sourceCode":"        Raises:\n            WebDriverException: Raised either when it can't start the service\n                or when it can't connect to the service\n        \"\"\"\n        if self._path is None:\n            raise WebDriverException(\"Service path cannot be None.\")\n        self._start_process(self._path)\n\n        count = 0\n        try:\n            while True:\n                self.assert_process_still_running()\n                if self.is_connectable():\n                    break\n                # sleep increasing: 0.01, 0.06, 0.11, 0.16, 0.21, 0.26, 0.31, 0.36, 0.41, 0.46, 0.5\n                sleep(min(0.01 + 0.05 * count, 0.5))\n                count += 1\n                if count == 70:\n                    raise WebDriverException(f\"Can not connect to the Service {self._path}\")\n        except BaseException:\n            try:\n                self.stop()\n            except Exception:\n                logger.error(\"Error stopping service after a failed start.\", exc_info=True)\n            raise\n\n    def assert_process_still_running(self) -> None:\n        \"\"\"Check if the underlying process is still running.\"\"\"\n        return_code = self.process.poll()\n        if return_code:\n            raise WebDriverException(f\"Service {self._path} unexpectedly exited. Status code was: {return_code}\")\n\n    def is_connectable(self) -> bool:\n        \"\"\"Check if the service is ready via the W3C WebDriver /status endpoint.\n\n        This makes an HTTP request to the /status endpoint and verifies if it is ready to accept new sessions.\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/service.py#L102-L138","documentation":"Raised by Service.start() after the driver process is running but the service never became connectable within the retry budget (70 iterations, ~30 seconds total, sleeping up to 0.5s each). The process did not exit (otherwise error 167 fires first), it simply never answered the W3C /status endpoint on its port. On failure the service is stopped automatically before re-raising.","triggerScenarios":"The driver binary launched and stays alive but does not open its HTTP port in time: a very slow machine, the driver waiting on a slow DNS/proxy, a port conflict where another process holds the port, or the driver started but is blocked by a firewall from listening on localhost. The is_connectable() check probes utils.is_url_connectable on the chosen port.","commonSituations":"Under-provisioned CI containers, driver version that hangs on startup (e.g. chromedriver waiting for a browser that is slow to spawn), antivirus/security software intercepting localhost connections, and port exhaustion or NAT issues inside containers.","solutions":["Increase available CPU/memory on the host or container; slow startup is the most common cause.","Check the driver log by passing log_output to the Service to see why it is not responding.","Verify the port is not already in use and that localhost loopback is not blocked by firewall/SELinux.","Pin a known-good driver/browser version pair if a recent update introduced slow startup.","Try a different port explicitly: Service(port=12345)."],"exampleFix":"# before — silent hang then failure\nservice = Service(executable_path='/path/chromedriver')\nservice.start()  # -> Can not connect to the Service ...\n\n# after — capture logs to diagnose\nservice = Service(executable_path='/path/chromedriver', log_output='/tmp/driver.log')\nservice.start()","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\nfor attempt in range(3):\n    try:\n        service = Service(executable_path=drv, log_output='/tmp/drv.log')\n        service.start()\n        break\n    except WebDriverException as e:\n        if 'Can not connect to the Service' in str(e) and attempt < 2:\n            continue\n        raise","preventionTips":["Pass log_output to the Service so startup failures are diagnosable.","Provision adequate CPU/memory on CI runners to avoid slow driver startup.","Ensure the chosen port is free and loopback is not firewalled."],"tags":["service","connectivity","timeout","startup","diagnostics"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}