Skip to content

fix: update executor and driver server URL state on directConnect - #2500

Open
hoanle0126 wants to merge 4 commits into
appium:masterfrom
hoanle0126:fix/direct-connect-server-url-state
Open

hoanle0126 wants to merge 4 commits into
appium:masterfrom
hoanle0126:fix/direct-connect-server-url-state

Conversation

@hoanle0126

@hoanle0126 hoanle0126 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Change list

  • Store the active client configuration and HTTP client in one immutable holder behind a single volatile field in AppiumCommandExecutor, synchronize overrideServerUrl, and read getAddressOfRemoteServer() directly from that configuration (populating the base URL from AppiumDriverLocalService when omitted).
  • Delegate AppiumDriver.getRemoteAddress directly to the command executor so callers (including SeleniumBridge and log broadcast listeners) see the updated server URL after directConnect or subsequent URL overrides.
  • Extract LogBroadcastEndpoints under io.appium.java_client.internal shared by ListensToLogcatMessages and ListensToSyslogMessages (keeping SessionHelpers focused on session-address parsing), deriving ws/wss directly from the active server URL while preserving the existing 0-arg and 1-arg default host and port (127.0.0.1:4723 / localhost:4723).
  • Move formatHost into io.appium.java_client.internal.Strings for shared IPv6 bracket normalization in both DirectConnect and LogBroadcastEndpoints.
  • Keep DirectConnect.isValid() checking non-null fields so blank protocol, host, or port values returned by a server still fail loudly in getUrl() with SessionNotCreatedException rather than silently falling back to the hub URL.

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

After the command executor became standalone in v11, overriding the server URL created a new HTTP client with the overridden base URL without updating the stored client configuration. That left the executor, driver remote address, and Selenium bridge configuration pointing to the initial hub URL after direct connect.

Added unit tests covering atomic executor state updates, Selenium bridge client configuration propagation, local service base URL fallback, nullable service constructor compatibility, HTTPS log broadcast wss derivation from the updated server URL while keeping legacy 0-arg/1-arg defaults, IPv6 / path normalization, and loud failure on blank direct-connect fields.

@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] ListensToSyslogMessages.java:69 and ListensToLogcatMessages.java:68 aren't in the diff, but this change affects them. They choose ws or wss from getAddressOfRemoteServer(), which now switches to https after directConnect. The host and port arguments still come from the caller, usually the original hub. startSyslogBroadcast(hubHost, 4723) now opens wss://hubHost:4723/... against a plain-WS port, where before this PR it used ws. Should these helpers also take the host and port from the updated URL, or should the scheme stay tied to the caller's endpoint?

@hoanle0126

Copy link
Copy Markdown
Contributor Author

Updated ListensToLogcatMessages and ListensToSyslogMessages so the no-arg startBroadcast() methods resolve host and port from getAddressOfRemoteServer() (falling back to 127.0.0.1:4723 / localhost:4723), while startBroadcast(host, port) only uses wss when (host, port) matches an https serverUrl (keeping explicit hub host/port calls on plain ws). Added unit tests covering both Android and iOS broadcast URIs.

@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 no-arg startLogcatBroadcast() and startSyslogBroadcast() now use the server's host and port instead of 127.0.0.1:4723 / localhost:4723. The one-arg overloads (startLogcatBroadcast(String host) and the syslog equivalent) still hard-code 4723. Against http://hub:4444, startLogcatBroadcast() connects to hub:4444, but startLogcatBroadcast("hub") connects to hub:4723. Should the one-arg overloads also default to the server port? The PR is marked non-breaking bugfix, but this is a behavior change for callers of the no-arg methods. If it's intended, please mention it in the description.
  • [minor] SessionHelpers is about session-address parsing. It now also holds log-broadcast URI logic: resolveBroadcastHost, resolveBroadcastPort, buildBroadcastUri and matchesEndpoint. The no-arg start logic is also copy-pasted between ListensToLogcatMessages.java:47 and ListensToSyslogMessages, down to the cast chain. Consider a small dedicated helper in io.appium.java_client.internal (for example a LogBroadcastEndpoints class) that resolves host and port from the executor and builds the URI. A fix like the wildcard-host one would then land in one place.

@hoanle0126

Copy link
Copy Markdown
Contributor Author

Addressed all review feedback in commit 8ee115c:

  • Extracted io.appium.java_client.internal.LogBroadcastEndpoints shared by ListensToLogcatMessages and ListensToSyslogMessages (removing duplicated cast/URI code from both interfaces and restoring SessionHelpers to session-address parsing only).
  • Updated 1-arg startLogcatBroadcast(host) / startSyslogBroadcast(host) to default to the active server port instead of hardcoded 4723, and documented the 0-arg / 1-arg server host & port defaulting behavior in the PR description.
  • Preserved wss for any https server unless targeting a replaced plain-http endpoint, mapped wildcard bind addresses (0.0.0.0 / [::]) to loopback, shared DirectConnect.formatHost, and restored loud SessionNotCreatedException failure on blank direct-connect fields.
  • Verified with ./gradlew test checkstyleMain checkstyleTest javadoc :selenium-bridge:check. Ready for re-review @mykola-mokhnach.

@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.

  • [critical] Undeclared breaking change (also anchored inline, comment 1). The PR is marked "Bugfix (non-breaking)" with no ! in the title and no BREAKING CHANGE: entry. The default host and port of the log-broadcast overloads change (details in the inline comment).

* is assigned to the default port (4723).
* This method uses the current remote server host (mapping wildcard addresses to {@code 127.0.0.1})
* and port when available, falling back to {@code 127.0.0.1:4723}.
*/

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.

[critical] This is an undeclared breaking change. The Javadoc for the no-arg and host-only startLogcatBroadcast / startSyslogBroadcast overloads documented a fixed default of 127.0.0.1 or localhost with port 4723. They now take host and port from the live server URL.

  • A user whose driver talks to https://hub.example.com/ (no explicit port) and who calls startLogcatBroadcast("127.0.0.1") now gets port 443 instead of 4723.
  • The no-arg form now connects to the hub host instead of loopback.

The overloads that behaved one way before now behave differently, and callers can't tell from the signature. Please mark the PR title with ! (e.g. fix!:). Add a BREAKING CHANGE: entry naming these four overloads and the migration path: pass host and port explicitly to keep the old endpoint. Or keep the old defaults and add the new behavior as opt-in.

return (AppiumCommandExecutor) remoteWebDriver.getCommandExecutor();
}

private static String chooseScheme(

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] chooseScheme and matchesEndpoint guess ws or wss by comparing host:port against a history of replaced http URLs. The guess includes loopback-equivalence and wildcard normalization. It is hard to reason about and needs the executor to track replaced URLs (see the next comment). Could the scheme come from the active server URL alone (https gives wss), or from an explicit parameter? If a heuristic is really needed, I'd split it into three steps: "is this endpoint the active server?", "was it a replaced plain-http one?", and "pick the scheme".

*
* @return unmodifiable list of replaced {@code http} server URLs
*/
public List<URL> getReplacedHttpServerUrls() {

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] getReplacedHttpServerUrls() is a new public method on a public class. It exists only so LogBroadcastEndpoints can pick a WebSocket scheme. That leaks a log-broadcast concern into the low-level executor and adds API that is hard to retract. Could it be package-private, or could the scheme decision move out of the executor (see the previous comment)?

* @param host the host name or IP literal
* @return the URL-safe host representation
*/
public static String formatHost(String host) {

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] DirectConnect.formatHost is public static, but only the internal LogBroadcastEndpoints uses it besides this class. That adds a new internal → remote dependency, and remote already depends on internal. Consider moving it to internal.Strings (or another internal helper) and calling it from both places, so it isn't public API.

@hoanle0126

Copy link
Copy Markdown
Contributor Author

Thanks @mykola-mokhnach! Updated PR #2500 to address all four review points:

  1. Backwards compatibility (non-breaking): Restored the original 127.0.0.1:4723 / localhost:4723 defaults and host/port contract on the 0-arg and 1-arg startLogcatBroadcast and startSyslogBroadcast overloads so existing callers keep the exact previous behavior and there is no breaking change.
  2. Simplified scheme derivation (LogBroadcastEndpoints): Removed chooseScheme, matchesEndpoint, and replaced-URL matching heuristics. buildBroadcastUri now derives ws / wss solely from the active server URL (https gives wss).
  3. Removed executor URL history API (AppiumCommandExecutor): Removed replacedHttpServerUrls from ClientState and dropped getReplacedHttpServerUrls() so no log-broadcast state or extra public API leaks out of the command executor.
  4. Moved formatHost (Strings): Moved formatHost from DirectConnect to io.appium.java_client.internal.Strings and called it from both DirectConnect and LogBroadcastEndpoints.

Updated the unit tests in LogBroadcastEndpointsTest, DirectConnectTest, and AppiumCommandExecutorTest as well as the PR description, and re-verified ./gradlew test checkstyleMain checkstyleTest javadoc :selenium-bridge:check. Ready for re-review!

This branch has not been deployed

No deployments
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