Repository navigation
fix: respect wsTimeout when opening WebSocket in JdkHttpClient - #2507
Merged
valfirst merged 3 commits intoNov 24, 2026
Merged
Conversation
JdkHttpClient previously ignored ClientConfig#wsTimeout() when opening a WebSocket connection, falling back to connectTimeout on the WebSocket builder and readTimeout (default 10 minutes) on the handshake future. - Store wsTimeout in JdkHttpClient from the provided ClientConfig. - Configure WebSocket.Builder#connectTimeout to wsTimeout when positive, avoiding IllegalArgumentException on Duration.ZERO. - Await the handshake future using wsTimeout (or indefinitely if zero). - Add unit tests verifying both handshake timeout and zero-timeout connection.
Abdelrhman-Ellithy
requested review from
SrinivasanTarget,
mykola-mokhnach,
saikrishna321 and
valfirst
as code owners
November 23, 2026 12:56
|
|
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
- [minor]
ClientConfig#wsTimeoutis not a WebSocket connect or handshake timeout in Selenium. AtSeleniumHQ/seleniummaster,BiDiProviderandRemoteWebDriveronly pass it tonew BiDi(connection, wsConfig.wsTimeout()), which is the BiDi command timeout. Selenium's ownJdkHttpClientstill usesconnectionTimeoutfor the WebSocket builder andreadTimeoutfor the handshakeget. The PR repurposes the setting, so the default handshake bound drops from 10 min (readTimeout) to 30 s (webdriver.httpclient.wsTimeout). Is that intended? If so, please say it in the PR description, and consider a Javadoc note thatconnectionTimeoutno longer applies to the WebSocket handshake.
mykola-mokhnach
left a comment
Contributor
There was a problem hiding this comment.
- [minor]
AppiumClientConfig.java:55(DEFAULT_WS_TIMEOUT): this PR changes the default WebSocket handshake bound fromreadTimeout(10 min) to 30 s. Users on slow proxies or device farms will seeinitial request timeoutafter upgrading. The description mentions it, but the PR is ticked as a "non-breaking bugfix" and has no!marker orBREAKING CHANGE:entry. Is this meant to be treated as a behavior change for release notes? If so, please mark it and add a short migration hint ("setwsTimeoutexplicitly to keep the old bound"). Arguably it just aligns with the documentedwsTimeoutcontract, so I'm asking rather than insisting. - [nit]
ClientConfig.java:56andAppiumClientConfig.java:237: the public API Javadoc links toio.appium.java_client.internal.http.JdkHttpClient. A public interface shouldn't reference an internal implementation class. Please describe the semantics generically (for example "the WebSocket handshake timeout; zero or negative values fall back toreadTimeout()") and drop the link.
mykola-mokhnach
approved these changes
Nov 23, 2026
valfirst
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change list
wsTimeoutinJdkHttpClientfrom the providedClientConfig.wsTimeoutas the single deterministic WebSocket handshake timeout viasocketFuture.get(...), falling back toreadTimeoutwhenwsTimeoutis zero or negative.WebSocket.Builder#connectTimeoutcall to avoid a dual-timer race between the JDK internal timer andsocketFuture.get(...).ClientConfig#wsTimeout()andAppiumClientConfig#wsTimeout(Duration)to consistently document the handshake timeout semantics and fallback behavior.JdkWebSocketTestverifying handshake timeout, zero-timeout fallback, and negative-timeout fallback.Types of changes
Details
JdkHttpClientpreviously ignoredClientConfig#wsTimeout()when opening a WebSocket connection viaopenSocket(...).Prior to this change:
java.net.http.WebSocket.Builder#connectTimeout(Duration)was hardcoded toconnectTimeout(the HTTP connect timeout, default 10s).socketFuture.get(...)usedreadTimeout(the HTTP read timeout, default 10 minutes).clientConfig.wsTimeout(...)had zero effect on WebSocket connection establishment, despiteClientConfig#wsTimeout()documenting it as "the maximum time to wait for a WebSocket connection to be established."This change wires
wsTimeoutas the single deterministic handshake timer:wsTimeoutis positive (wsTimeout.compareTo(Duration.ZERO) > 0), it is used directly as thesocketFuture.get(...)deadline.wsTimeoutis zero or negative, the handshake falls back toreadTimeout(preserving the pre-PR bounded behavior, default 10 minutes).WebSocket.Builder#connectTimeout(...)is no longer set separately, eliminating the dual-timer race that could produce inconsistent error messages (ExecutionExceptionwrappingHttpTimeoutExceptionvs.TimeoutException). The underlyingHttpClientstill retains its ownconnectTimeoutfor TCP connection establishment.Note: This intentionally changes the default WebSocket handshake bound from
readTimeout(10 min) towsTimeout(30 s, viaAppiumClientConfig.DEFAULT_WS_TIMEOUT), matching theClientConfig#wsTimeout()interface contract.If your environment (e.g., slow proxies or remote device farms) relies on the previous 10-minute default, set wsTimeout explicitly on AppiumClientConfig.
Verification
timesOutWhenWebSocketHandshakeDoesNotComplete: Confirms a stalled handshake aborts atwsTimeout(200ms) rather thanreadTimeout(5m) orconnectTimeout(10s), and asserts the deterministic"initial request timeout"error message.fallsBackToReadTimeoutWhenWsTimeoutIsZero: ConfirmsDuration.ZEROfalls back toreadTimeout(200ms) instead of waiting indefinitely.fallsBackToReadTimeoutWhenWsTimeoutIsNegative: Confirms negativewsTimeoutfalls back toreadTimeout(200ms) instead of failing immediately.