square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.84k stars 9.16k forks source link

Happy Eyeballs Dns is synchronous and combined across IPv4/6 #8089

Open alanhu-dev opened 1 year ago

alanhu-dev commented 1 year ago

Hello, esteemed developers. I'm currently trying to integrate Volley and OkHttp in our project. Our network layer relies on Volley, but we also want to leverage OkHttp's new feature: Happy Eyeballs. Below is a code snippet of how I've integrated them, and everything seems to work as expected, both in terms of requests and responses. However, it appears that the Happy Eyeballs feature isn't taking effect. When I use Wireshark to monitor the network traffic, I can clearly see that both IPv6 and IPv4 records are being sent out, but the response for IPv4 arrives much earlier. Nevertheless, it continues to wait until the IPv6 response comes in before proceeding to call the API.

implementation "com.android.volley:volley:1.2.1"

implementation platform("com.squareup.okhttp3:okhttp-bom:5.0.0-alpha.11")
implementation "com.squareup.okhttp3:okhttp"
implementation "com.squareup.okhttp3:okhttp-tls"
implementation "com.squareup.okhttp3:okhttp-dnsoverhttps"
implementation "com.squareup.okhttp3:logging-interceptor"

https://gist.github.com/SUPERYAO541/1000c3d77c13c3609a54633eed008d5f

Wireshark (only 1 api call) https://i.imgur.com/sDh6lKR.png

yschimke commented 1 year ago

Yep, that is a current limitation.

The current fastFallback code is using the synchronous Dns API here

https://github.com/square/okhttp/blob/c73f9842ad72e4169f2c2f149b5bdee83fb73a76/okhttp/src/jvmMain/kotlin/okhttp3/internal/connection/RouteSelector.kt#L169

        eventListener.dnsStart(call, socketHost)

        val result = address.dns.lookup(socketHost)

We have a new AsyncDns API, and an Android implementation but it's not yet wired up fully.

We should leave this open as it's worth progressing, but I think once fastFallback resolved bad IPv6 network setups, this took a back seat.