Repository navigation
fix: update executor and driver server URL state on directConnect - #2500
hoanle0126 wants to merge 3 commits into
Conversation
mykola-mokhnach
left a comment
There was a problem hiding this comment.
- [minor]
ListensToSyslogMessages.java:69andListensToLogcatMessages.java:68aren't in the diff, but this change affects them. They choosewsorwssfromgetAddressOfRemoteServer(), which now switches tohttpsafter directConnect. Thehostandportarguments still come from the caller, usually the original hub.startSyslogBroadcast(hubHost, 4723)now openswss://hubHost:4723/...against a plain-WS port, where before this PR it usedws. Should these helpers also take the host and port from the updated URL, or should the scheme stay tied to the caller's endpoint?
|
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
left a comment
There was a problem hiding this comment.
- [minor] The no-arg
startLogcatBroadcast()andstartSyslogBroadcast()now use the server's host and port instead of127.0.0.1:4723/localhost:4723. The one-arg overloads (startLogcatBroadcast(String host)and the syslog equivalent) still hard-code 4723. Againsthttp://hub:4444,startLogcatBroadcast()connects tohub:4444, butstartLogcatBroadcast("hub")connects tohub: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]
SessionHelpersis about session-address parsing. It now also holds log-broadcast URI logic:resolveBroadcastHost,resolveBroadcastPort,buildBroadcastUriandmatchesEndpoint. The no-arg start logic is also copy-pasted betweenListensToLogcatMessages.java:47andListensToSyslogMessages, down to the cast chain. Consider a small dedicated helper inio.appium.java_client.internal(for example aLogBroadcastEndpointsclass) 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.
| @Nullable SessionId sessionId, | ||
| String deviceLogType | ||
| ) { | ||
| String scheme = serverUrl != null |
There was a problem hiding this comment.
[major] wss is now chosen only when the host and port exactly match the https server URL. Before, any https server gave wss. Take an https hub at https://grid.example.com (443) with a separate log host, for example startLogcatBroadcast("10.0.0.5", 443) or an IP-vs-DNS alias. Another case is a TLS proxy on a non-Appium port, called through startLogcatBroadcast(host), which uses port 4723 and never matches. Those calls now produce ws://, and a TLS-only endpoint rejects it. This is a silent regression for existing callers. Is it intended? If so, it needs the ! marker and a BREAKING CHANGE: entry with the migration path. Otherwise, could it keep wss for any https server and only fix the direct-connect case?
There was a problem hiding this comment.
Addressed in 8ee115c: preserved wss for any https server across all overloads (separate log hosts, TLS proxies, IP-vs-DNS aliases), while tracking replaced plain-http server URLs in AppiumCommandExecutor.ClientState so only calls matching a plain-http endpoint overridden by directConnect (and not the active serverUrl) keep ws. Covered in LogBroadcastEndpointsTest and AppiumCommandExecutorTest.
| * @param fallbackHost the host to return when {@code serverUrl} has no host | ||
| * @return the resolved broadcast host | ||
| */ | ||
| public static String resolveBroadcastHost(@Nullable URL serverUrl, String fallbackHost) { |
There was a problem hiding this comment.
[minor] resolveBroadcastHost returns the raw server host. AppiumDriverLocalService.getUrl() can return http://0.0.0.0:4723 or http://[::]:4723, and the service already normalizes those in fixBroadcastAddresses. The executor now takes its base URL from the service, so the no-arg startLogcatBroadcast() would build ws://0.0.0.0:4723/.... It used to go through 127.0.0.1, and connecting to a wildcard address fails on Windows and some stacks. Could wildcard hosts map to the loopback fallback here?
There was a problem hiding this comment.
Addressed in 8ee115c: LogBroadcastEndpoints.resolveHost now maps wildcard bind hosts (0.0.0.0, [::], [0:0:0:0:0:0:0:0]) to the loopback fallback (127.0.0.1 / localhost), with unit tests in LogBroadcastEndpointsTest and AppiumCommandExecutorTest.
| * Returns true if the {@link DirectConnect} instance member has valid values. | ||
| * @return true if protocol, host and port are non-blank and path is non-null | ||
| */ | ||
| public boolean isValid() { |
There was a problem hiding this comment.
[minor] isValid() now returns false for blank protocol, host or port, and setDirectConnect silently returns on invalid. A response such as directConnectHost: "x" with directConnectPort: "" used to fail with SessionNotCreatedException. Now it is silently ignored and the session keeps using the hub URL, which hides the server misconfiguration. Should blank values still fail loudly, or at least be logged?
There was a problem hiding this comment.
Addressed in 8ee115c: restored DirectConnect.isValid() to check non-null fields and moved the non-blank validation for protocol, host, and port into getUrl(), so blank direct-connect values (e.g. directConnectPort: "") fail loudly with SessionNotCreatedException again instead of silently falling back to the hub URL.
| return trimmed; | ||
| } | ||
|
|
||
| private static String formatHost(String host) { |
There was a problem hiding this comment.
[nit] This duplicates DirectConnect.formatHost, so the two can drift apart. Could the two share one helper?
There was a problem hiding this comment.
Addressed in 8ee115c: exposed DirectConnect.formatHost as public static and reused it in LogBroadcastEndpoints.buildBroadcastUri, removing the duplicate helper.
|
Addressed all review feedback in commit 8ee115c:
|
Change list
AppiumCommandExecutor, synchronizeoverrideServerUrl, and readgetAddressOfRemoteServer()directly from that configuration (populating the base URL from AppiumDriverLocalService when omitted).AppiumDriver.getRemoteAddressdirectly to the command executor so callers (includingSeleniumBridgeand log broadcast listeners) see the updated server URL afterdirectConnector subsequent URL overrides.LogBroadcastEndpointsunder io.appium.java_client.internal shared byListensToLogcatMessagesandListensToSyslogMessages(keeping SessionHelpers focused on session-address parsing), mapping wildcard bind hosts (0.0.0.0 / [::]) to loopback fallback and sharing DirectConnect.formatHost.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
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.
Note on log broadcast defaults: the 0-arg startLogcatBroadcast() / startSyslogBroadcast() and 1-arg startLogcatBroadcast(host) / startSyslogBroadcast(host) overloads now resolve default host (mapping 0.0.0.0 / [::] to the loopback fallback) and default port from the active server URL rather than hardcoding 127.0.0.1:4723 / localhost:4723. Callers that need another endpoint should pass both host and port explicitly.
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 scheme preservation vs replaced plain-HTTP hub endpoints, wildcard bind host mapping, 1-arg server port defaulting, IPv6 / path normalization, and loud failure on blank direct-connect fields.