SeleniumHQ/selenium · error · WebDriverException
Service {self._path} unexpectedly exited. Status code was: {
Error message
Service {self._path} unexpectedly exited. Status code was: {return_code} What it means
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.
Source
Thrown at py/selenium/webdriver/common/service.py:132
if self.is_connectable():
break
# sleep increasing: 0.01, 0.06, 0.11, 0.16, 0.21, 0.26, 0.31, 0.36, 0.41, 0.46, 0.5
sleep(min(0.01 + 0.05 * count, 0.5))
count += 1
if count == 70:
raise WebDriverException(f"Can not connect to the Service {self._path}")
except BaseException:
try:
self.stop()
except Exception:
logger.error("Error stopping service after a failed start.", exc_info=True)
raise
def assert_process_still_running(self) -> None:
"""Check if the underlying process is still running."""
return_code = self.process.poll()
if return_code:
raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
def is_connectable(self) -> bool:
"""Check if the service is ready via the W3C WebDriver /status endpoint.
This makes an HTTP request to the /status endpoint and verifies if it is ready to accept new sessions.
Returns:
True if the service is ready to accept new sessions, False otherwise.
"""
return utils.is_url_connectable(self.port)
def send_remote_shutdown_command(self) -> None:
"""Dispatch an HTTP request to the shutdown endpoint to stop the service."""
try:
request.urlopen(f"{self.service_url}/shutdown", timeout=10)
except (URLError, TimeoutError):
return
View on GitHub (pinned to aa36b38e69)
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.
Example fix
# before — driver exits immediately, no clue why service = Service(executable_path='/old/chromedriver') service.start() # -> unexpectedly exited. Status code was: 2 # after — log driver stderr and let manager choose service = Service(log_output='/tmp/driver.log') driver = webdriver.Chrome(service=service)
Defensive patterns
Strategy: try-catch
Validate before calling
import subprocess
rc = subprocess.run([drv, '--version'], capture_output=True).returncode
if rc:
raise SystemExit(f'driver {drv} failed self-check (rc={rc}); likely version mismatch') Type guard
null
Try / catch
from selenium.common.exceptions import WebDriverException
try:
service.start()
except WebDriverException as e:
if 'unexpectedly exited' in str(e):
# parse status code, align driver/browser versions, or let Selenium Manager pick Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can not connect to the Service {self._path}
- Unsuccessful command executed: {command}; code: {completed_p
- Service path cannot be None.
- SE_MANAGER_PATH does not point to a file: {env_path}
- Unsuccessful command executed: {command}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/39772de87d816517.
Report an issue: GitHub.