Repository navigation
fix: update executor and driver server URL state on directConnect - #2500
hoanle0126 wants to merge 7 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.
|
Addressed all review feedback in commit 8ee115c:
|
mykola-mokhnach
left a comment
There was a problem hiding this comment.
- [critical] Undeclared breaking change (also anchored inline, comment 1). The PR is marked "Bugfix (non-breaking)" with no
!in the title and noBREAKING CHANGE:entry. The default host and port of the log-broadcast overloads change (details in the inline comment).
|
Thanks @mykola-mokhnach! Updated PR #2500 to address all four review points:
Updated the unit tests in |
| @Nullable SessionId sessionId, | ||
| String deviceLogType | ||
| ) { | ||
| String scheme = serverUrl != null && "https".equalsIgnoreCase(serverUrl.getProtocol()) ? "wss" : "ws"; |
There was a problem hiding this comment.
[P2] Restoring the host and port defaults still leaves a compatibility issue here. Suppose the session starts at http://hub:4723, direct-connects to an HTTPS node, and the caller uses startLogcatBroadcast("hub", 4723) to reach the original plain-WS endpoint. Before this PR that call opened ws://hub:4723/.... This line now selects wss://hub:4723/..., so the TLS handshake fails. The same applies to syslog. Could the existing overloads retain the original scheme and have a regression test for this case? If the change is intentional, please document the compatibility impact and how callers can still select ws.
There was a problem hiding this comment.
Good catch, thanks! Updated LogBroadcastEndpoints to pick the WebSocket scheme from the executor's initial server URL (before any directConnect or URL override) via an internal bridge so AppiumCommandExecutor does not add new public API.
Sessions starting on plain HTTP now stay on ws for both logcat and syslog broadcasts after direct-connecting to HTTPS, while initial HTTPS sessions keep using wss. Added regression tests covering both cases plus null initial base URL in AppiumCommandExecutorTest.
|
@hoanle0126 could you please resolve merge conflicts? |
|
@mykola-mokhnach Merged master and resolved the conflict in |
|
@hoanle0126 Are you sure we still would like to invest into the deprecated logging APIs? |
|
@mykola-mokhnach That part was added for @KazuCocoa's P2 review so explicit logcat and syslog calls keep their initial ws/wss scheme after directConnect until those APIs are removed in the next major bump. Since it's already implemented and tested, keeping it avoids an 11.x regression unless you prefer dropping it. |
This makes sense, although it would be still necessary to check which parts are only used by deprecated entities and mark them as deprecated as well, so we don't have unexpected leftovers after the future cleanup. |
mykola-mokhnach
left a comment
There was a problem hiding this comment.
- [minor] The PR title and description are about syncing executor and driver server URL state after
directConnect. The PR also adds theStrings.formatHostIPv6 bracketing, newDirectConnect.getUrl()normalization and validation, and theLogBroadcastEndpointsrefactor of the logcat and syslog listeners. The first of these rides along with the others in afix:PR, so it can't be reverted separately. Consider splitting the logcat/syslog refactor and theDirectConnecthardening into their own PRs.
| } | ||
|
|
||
| @Nullable | ||
| private static URL resolveInitialServerUrl(AppiumCommandExecutor executor) { |
There was a problem hiding this comment.
[minor] resolveInitialServerUrl plus the CommandExecutorInternals registry (AtomicReference, MethodHandles.Lookup check, compareAndSet, SecurityException) is a lot of machinery just to read one field from the same module.
- The method has redundant branches.
state == nullcan't happen after construction. The last two lines readclientStatea second time, which can disagree with the first read under a concurrent override. - A subclass that overrides
getAddressOfRemoteServer()gets its own value before an override butinitialServerUrlafter one. The scheme for log broadcasts then depends on call history.
Could LogBroadcastEndpoints get the scheme without a static registry? For example, AppiumCommandExecutor could expose a small accessor, or the initial scheme could be stored in an internal holder. At minimum, collapse the method to return executor.initialServerUrl;.
| String.format("The remote server returned an invalid value to build the direct connect URL: %s", | ||
| newUrlCandidate) | ||
| ); | ||
| URL url = new URL(newUrlCandidate); |
There was a problem hiding this comment.
[minor] getUrl() concatenates server-supplied host and port and then parses the result. It never checks that the parsed URL has the same host and port. LogBroadcastEndpoints.buildBroadcastUri does make that check.
- For
host="evil.com/x", orport="4443/foo",new URL(...)andtoURI()both succeed. The result ishost=evil.comwith no port, and the rest goes into the path. DirectConnectUrlSafetyvalidates onlyurl.getHost(), so the client can connect to a different authority or port than the server advertised.
Please compare url.getHost() and url.getPort() against the input fields and throw MalformedURLException on a mismatch. Add a test for the host/path case.
|
@mykola-mokhnach Done in b6e90f5. Marked |
Change list
AppiumCommandExecutor, populate the base URL from AppiumDriverLocalService when omitted, and guardoverrideServerUrlswaps with a private lock outside DNS validation and old client cleanup.AppiumDriver.getRemoteAddressto the command executor so driver callers see the updated server URL afterdirectConnector subsequent overrides, while SeleniumBridge reads the updated base URI fromgetAppiumClientConfig().LogBroadcastEndpointsandCommandExecutorInternalsunderio.appium.java_client.internalso logcat and syslog listeners share WebSocket setup while keeping 0-argstartLogcatBroadcast()on the connected server URL (omitting absent ports) and preserving the initial server URL's ws/wss scheme before overrides for explicit-host logcat and syslog overloads.Strings.formatHostfor IPv6 bracket formatting, accept uppercase https in setDirectConnect, and updateDirectConnect.getUrl()to prepend a leading slash to relative paths (leaving empty paths unchanged) and throw MalformedURLException on blank or non-URI direct-connect fields.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 config or cached remote address. As a result, getAddressOfRemoteServer(), AppiumDriver.getRemoteAddress(), and SeleniumBridge kept pointing at the initial hub URL after direct connect.
Added unit tests covering server URL and config updates on direct connect, Selenium bridge config propagation, local service base URL fallback, nullable service constructor compatibility, connected-server default logcat broadcast alongside initial ws/wss scheme retention for explicit-host and syslog overloads, host and port validation in broadcast URIs, IPv6 and path normalization, and rejecting malformed or blank direct-connect fields.