Repository navigation
Try every resolved address when connecting a TCP socket - #2214
Merged
Merged
Conversation
TcpStreamSocketJava connected only to the first address the host resolved to. On a network where IPv6 is assigned but broken, a host with both IPv6 and IPv4 addresses resolves IPv6 first, that address refuses or times out, and the stream fails although the server is reachable over IPv4. Now every resolved address is tried in the system order within the original timeout (each one gets an equal share of the time left). Only the TCP connect moves on to the next address; a TLS handshake error is reported as it is. The host name is kept in the connected address, so SNI and certificate checks are unchanged.
Owner
|
Thank you for the PR. Merged |
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.
Problem
TcpStreamSocketJava.onConnectSocketconnects toInetSocketAddress(host, port), which uses only the first address the host resolves to. On Android, when the device has an IPv6 address, dual-stack ingest hosts usually resolve IPv6 first. If IPv6 is assigned on that network but doesn't work, the connect is refused or times out and the stream doesn't start, even though the same server answers over IPv4. Browsers and OkHttp move on to the next address, so for the user "the internet works" but streaming doesn't.We saw this pattern in our app's reports: one device failed to connect to both YouTube and Twitch ingest over IPv6 (
isConnected failed: ECONNREFUSED), and those connects were never tried over IPv4. The report can't tell us whether IPv4 would have worked on that network, so please treat this as a robustness change, not a proven fix for that case.Change
InetAddress.getByAddress(host, bytes)), so SNI and hostname verification work as before.resolveris an internal property, only to make this testable.Ktor sockets (
SocketType.KTOR) are not changed here.Testing
common(TcpStreamSocketJavaTest): fallback from a failing first address to a working one, first address used when it works, host name kept, and an error when no address connects../gradlew :common:testDebugUnitTest(102 tests) and./gradlew :rtmp:testDebugUnitTest(59 tests) pass locally.🤖 Generated with Claude Code