Skip to content

fix: propagate HTTP version and sync quit state in selenium-bridge - #2510

Merged
mykola-mokhnach merged 4 commits into
appium:masterfrom
Abdelrhman-Ellithy:fix/selenium-bridge-version-and-quit
Nov 26, 2026
Merged

mykola-mokhnach merged 4 commits into
appium:masterfrom
Abdelrhman-Ellithy:fix/selenium-bridge-version-and-quit

Conversation

@Abdelrhman-Ellithy

@Abdelrhman-Ellithy Abdelrhman-Ellithy commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Change list

  • Forward AppiumClientConfig#version() to Selenium's ClientConfig in BridgedRemoteWebDriver#toSeleniumConfig(...) when non-null, and update docs/selenium-bridge.md.
  • Route DriverCommand.QUIT in SeleniumCommandExecutor through delegate.quit() when quit is enabled so both BridgedRemoteWebDriver and AppiumRemoteWebDriver clear their sessionId with a single DELETE /session/:id request.
  • Check driver.getSessionId() == null up front in both SeleniumBridge.asRemoteWebDriver(...) overloads, evict any stale cached bridge lazily in SeleniumBridge.asRemoteWebDriver(AppiumRemoteWebDriver), and fail fast with IllegalStateException.
  • Extract closeBiDiAfterQuit(@Nullable Throwable) in BridgedRemoteWebDriver#quit() with constructor-rollback null guards so any primary failure from super.quit() is preserved and closeBiDi() exceptions are attached via addSuppressed.
  • Add unit tests in SeleniumBridgeTest covering HTTP version forwarding, single-DELETE quit synchronization, delegate-quit-first idempotency, lazy eviction + IllegalStateException checks, closeBiDi() failure propagation/suppression, and cleanup when quit() fails.

Types of changes

  • No changes in production code.
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Details

  1. HTTP version dropped in bridge config: BridgedRemoteWebDriver#toSeleniumConfig forwarded timeouts, proxy, credentials, and SSL context from AppiumClientConfig, but omitted source.version(), ignoring configured HTTP versions (e.g. HTTP_2).
    • Behavior note: AppiumClientConfig.defaultConfig().version() defaults to "HTTP_1_1", whereas Selenium's ClientConfig.defaultConfig().version() defaults to null (falling back to JDK HttpClient's default). Forwarding source.version() when non-null intentionally aligns the bridged client with the driver's AppiumClientConfig (matching the existing timeout/proxy/credentials/SSL forwarding); callers wanting "HTTP_2" or null can configure it on AppiumClientConfig.
  2. Asymmetric quit() state & stale bridge cache: Calling seleniumDriver.quit() previously sent DELETE /session/:id directly through delegate.getCommandExecutor(), bypassing AppiumRemoteWebDriver#quit() and leaving delegate.getSessionId() non-null while a cached bridge could remain in SeleniumBridge.BRIDGES. Routing DriverCommand.QUIT through delegate.quit() keeps both drivers synchronized with a single DELETE request, even when the server returns an error on quit. Subsequent SeleniumBridge.asRemoteWebDriver(...) calls check driver.getSessionId() == null up front, evict lazily from BRIDGES on the cached overload, and fail fast with IllegalStateException. In BridgedRemoteWebDriver#quit(), closeBiDiAfterQuit(...) handles constructor rollback if super(...) invokes quit() before webSocketClients is initialized and keeps super.quit() exceptions primary when closeBiDi() also throws.

(Note: Kept strictly scoped to selenium-bridge without modifying AppiumRemoteWebDriver#quit().

Verification

  • Ran ./gradlew :checkstyleMain :javadoc :selenium-bridge:checkstyleMain :selenium-bridge:checkstyleTest :selenium-bridge:javadoc :selenium-bridge:test (18/18 tests passing, no new warnings).

@mykola-mokhnach mykola-mokhnach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [minor] BridgedRemoteWebDriver.java:84: the eviction only runs when the bridge's own quit() is called. After appiumDriver.quit() alone, a later SeleniumBridge.asRemoteWebDriver(appiumDriver) still returns the cached bridge, because isBiDiClosed() is false. That bridge has a dead session and an open WebSocket. I understand this is out of scope for the PR. Even so, should asRemoteWebDriver check driver.getSessionId() == null on the cached path, then evict, close BiDi and fail fast? doesNotSendDuplicateDeleteWhenDelegateQuitFirst only passes the eviction assertion because it also calls seleniumDriver.quit() afterwards.
  • [nit] docs/selenium-bridge.md:19-20 and the SeleniumBridge.asRemoteWebDriver Javadoc: they say the same instance is returned while BiDi is open. They don't mention that after quit() the cache entry is gone and a new asRemoteWebDriver(...) call throws SessionNotCreatedException.

@mykola-mokhnach mykola-mokhnach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No general findings. The change looks correct; the inline notes are minor and nit.

@Abdelrhman-Ellithy

Copy link
Copy Markdown
Contributor Author

@mykola-mokhnach addressed all four notes in the last commit.

@mykola-mokhnach mykola-mokhnach left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • [minor] The PR description no longer matches the code. It says BridgedRemoteWebDriver#quit() evicts the delegate from BRIDGES in finally, with constructor-rollback guards alongside closeBiDi(). The last commit moved eviction into SeleniumBridge.asRemoteWebDriver(...), which evicts lazily when the driver has no session. Please update the Change list and Details so the description says that.

*/
@Override
public void quit() {
Throwable quitFailure = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] quit() now nests try/catch/finally/try/catch, with the null guard and suppression bookkeeping in the middle. Consider extracting the cleanup into a helper such as closeBiDiAfterQuit(Throwable quitFailure). It would do the null guard, call closeBiDi(), and either rethrow or addSuppressed. quit() would then read as "super.quit(), then close BiDi, keeping the quit failure as primary".

@mykola-mokhnach
mykola-mokhnach merged commit 156f5ab into appium:master Nov 26, 2026
13 checks passed
@Abdelrhman-Ellithy
Abdelrhman-Ellithy deleted the fix/selenium-bridge-version-and-quit branch November 26, 2026 20:21
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.

3 participants