Skip to content

Add retry logic to Firefox driver startup#1580

Merged
akoeplinger merged 2 commits intomainfrom
fix/firefox-driver-retry
Apr 4, 2026
Merged

Add retry logic to Firefox driver startup#1580
akoeplinger merged 2 commits intomainfrom
fix/firefox-driver-retry

Conversation

@lewing
Copy link
Copy Markdown
Member

@lewing lewing commented Apr 3, 2026

Summary

Adds the same startup retry logic that Chrome/Edge already have to the Firefox (geckodriver) path.

Problem

GetFirefoxDriver uses CreateWebDriver which tries once and throws on failure. GetChromiumDriver has a 3-attempt retry loop. When geckodriver takes time to bind to its port, xharness gets repeated Connection refused errors followed by WebDriverException: Cannot start the driver service and exits with code 71 (GENERAL_FAILURE).

This is a known CI flake pattern — dotnet/runtime#104349 tracked the same Connection refused issue and had BuildRetry: true as a workaround.

Example from dotnet/runtime build 1365445:

Connection refused [::ffff:127.0.0.1]:42115 (localhost:42115)
... (repeated ~45 times)
geckodriver INFO Listening on 127.0.0.1:42115
OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:42115/

Fix

  • Add retry loop (3 attempts) to GetFirefoxDriver matching the Chromium pattern
  • Catch WebDriverException with known retryable error snippets: Cannot start the driver service, Connection refused, exited abnormally, failed to start
  • Enable verbose geckodriver logging per attempt for diagnosis
  • Properly dispose driver service on failure before retry

Prior art

GetFirefoxDriver used CreateWebDriver which has no retry, while
GetChromiumDriver has a 3-attempt retry loop for transient startup
failures. This causes flaky CI failures when geckodriver takes time
to bind to its port — xharness gets 'Connection refused' errors
followed by 'Cannot start the driver service' and exits with code 71.

Add the same retry pattern to GetFirefoxDriver: 3 attempts with
retryable error snippets including 'Cannot start the driver service'
and 'Connection refused'. Also enable verbose geckodriver logging
to aid future diagnosis.

Related: dotnet/runtime#104349, dotnet/runtime#126489

Co-authored-by: Copilot <[email protected]>
@lewing lewing requested a review from akoeplinger April 3, 2026 17:40
…iverService

FirefoxDriverService in Selenium 4.0.0-alpha05 does not have
EnableAppendLog, EnableVerboseLogging, or LogPath properties.
These are ChromiumDriverService-specific. Remove them from the
Firefox retry loop.

Co-authored-by: Copilot <[email protected]>
@akoeplinger akoeplinger merged commit 0668c80 into main Apr 4, 2026
17 checks passed
@akoeplinger akoeplinger deleted the fix/firefox-driver-retry branch April 4, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants