{"record":{"id":"39772de87d816517","repo":"SeleniumHQ/selenium","slug":"service-self-path-unexpectedly-exited-status-c","errorCode":null,"errorMessage":"Service {self._path} unexpectedly exited. Status code was: {return_code}","messagePattern":"Service (.+?) unexpectedly exited\\. Status code was: (.+?)","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/service.py","lineNumber":132,"sourceCode":"                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\n        Returns:\n            True if the service is ready to accept new sessions, False otherwise.\n        \"\"\"\n        return utils.is_url_connectable(self.port)\n\n    def send_remote_shutdown_command(self) -> None:\n        \"\"\"Dispatch an HTTP request to the shutdown endpoint to stop the service.\"\"\"\n        try:\n            request.urlopen(f\"{self.service_url}/shutdown\", timeout=10)\n        except (URLError, TimeoutError):\n            return\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/service.py#L114-L150","documentation":"Raised by Service.assert_process_still_running() when the child driver process has already exited (process.poll() returns a non-None return code) before the service became connectable. Unlike error 166 (process alive but not answering), here the driver crashed during startup. The status code is included to aid diagnosis.","triggerScenarios":"The driver binary exits immediately: wrong driver for the installed browser version, the driver cannot find the browser executable, a missing system library causes the driver to abort, the driver was killed by the OS (OOM killer), or the driver rejected its command-line arguments.","commonSituations":"chromedriver/geckodriver version mismatched to the browser (status code 2), browser not installed (status code varies), missing libgbm/libnss on headless Linux, and passing invalid Service args that the driver rejects on startup.","solutions":["Use the status code: status 2 commonly means version mismatch — align driver and browser versions.","Capture driver output via log_output to read the driver's own error message.","Ensure the browser binary is installed and discoverable; on Linux install required shared libraries.","Validate any custom service_args/command_line_args you pass; remove unsupported flags.","Let Selenium Manager pick a compatible driver instead of pinning an old one."],"exampleFix":"# before — driver exits immediately, no clue why\nservice = Service(executable_path='/old/chromedriver')\nservice.start()  # -> unexpectedly exited. Status code was: 2\n\n# after — log driver stderr and let manager choose\nservice = Service(log_output='/tmp/driver.log')\ndriver = webdriver.Chrome(service=service)","handlingStrategy":"try-catch","validationCode":"import subprocess\nrc = subprocess.run([drv, '--version'], capture_output=True).returncode\nif rc:\n    raise SystemExit(f'driver {drv} failed self-check (rc={rc}); likely version mismatch')","typeGuard":"null","tryCatchPattern":"from selenium.common.exceptions import WebDriverException\ntry:\n    service.start()\nexcept WebDriverException as e:\n    if 'unexpectedly exited' in str(e):\n        # parse status code, align driver/browser versions, or let Selenium Manager pick","preventionTips":["Let Selenium Manager select a compatible driver rather than pinning an old one.","Smoke-test the driver with --version in CI before launching the browser.","Install required shared libraries for the driver on headless Linux."],"tags":["service","process-exit","version-mismatch","startup","diagnostics"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}