ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

How to change the DNS server used by ExoPlayer

Open Lohit-Huddar opened this issue 2 years ago • 6 comments

ExoPlayer Version

2.16.1

Devices that reproduce the issue

Any android device

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Sometimes, ISP does fail to resolve hostname to IP and player ends up in below error,

Exception caught : HttpDataSourceException: Unable to connect to myhostname.com, Unable to resolve host myhostname.com: No address associated with hostname, android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)

How to set external DNS server url on exoplayer so that all master, variant and segment request by player uses newly set DNS server to resolve hostname to IP and streaming works fine. Or any option to set backup DNS url so that exoplayer can internally use it if at first attempt it's not able to resolve host.

This issue is seen in field and not locally reproducible since its related to ISP not resolving hostname. It's seen across domain names and using external DNS servers would help to resolve IP which fixes playback failure issues.

Tried browsing through multiple forums, no luck and hence raising ticket here.

Expected result

API to set DNS server url

Actual result

Exception thrown by player mentioning "No address associated with hostname" leading to playback failure.

Media

Any media url

Bug Report

  • [ ] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

Lohit-Huddar avatar Jul 15 '22 06:07 Lohit-Huddar

I'm not aware that there is an Android API that lets an app set the DNS server. I don't think that resolving the host name is part of the HTTP stack but is provided to the HTTP stack by the OS. A user can change the DNS server in the settings and I actually think this shouldn't be overridden by an app. But that's my opinion which doesn't count as an argument whether there is such an API or not. :)

In any case, if this is possible then it's not an ExoPlayer API that provides this.

I leave this issue open in case someone else knows more details about this.

marcbaechinger avatar Jul 15 '22 12:07 marcbaechinger

@Lohit-Huddar is the error message that you posted accurate or have you modified it before copying here? That is

Exception caught : HttpDataSourceException: Unable to connect to Unable to resolve host ".com": No address associated with hostname, android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)

indicates the player tried to download from the hostname .com. Did you reduct the hostname? If not, and this is the actual hostname, I'd assume there's an error/bug elsewhere and not the device's DNS server settings.

christosts avatar Jul 15 '22 12:07 christosts

Firstly, thanks @marcbaechinger and @christosts for quick check and reply.

Looks like its github editor issue, I modified the original hostname to myhostname.com in description where i had kept myhostname.com within <>, but github editor removed myhostname and retained only .com.

I edited my original description, please consider myhostname.com as proper domain name, cant paste original hostname for confidentiality reason.

curl library has option to set DNS server url, i was expecting something similar in DefaultHttpDataSource or DataSpec but no options i see.

Curl API: curl_easy_setopt(m_curl, CURLOPT_DOH_URL, m_dnsUrl.c_str());

Lohit-Huddar avatar Jul 15 '22 12:07 Lohit-Huddar

@marcbaechinger is correct, there is no API in Android to set the DNS resolution the system will use, that would be a pretty big security whole.

@Lohit-Huddar If you use the OkHTTP extension with ExoPlayer (https://exoplayer.dev/network-stacks.html) then that client (OkHttp3) allows you to specify a Dns interface (https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dns/) maybe not perfectly what you want, but this gives you a hook to resolve the name yourself. You still need your own mechanism to resolve name to InetAddress, either hard coding host to IP or a Java DNS client.

So, not sure this solves your problem but it answers the question.

FWIW, Many ISP's (AT&T GigaFiber here in the US for example) go to great lengths to block user control of the address of a DNS server used for name resolution, this is done for tracking and selling more advertisement. This will cause even more pain then a simple recover from an NXDOMAIN. For example, here's a bogus lookup from an AT&T provided DNS:

$ dig awafrewafkelwke.com

; <<>> DiG 9.10.6 <<>> awafrewafkelwke.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 19282
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;awafrewafkelwke.com.		IN	A

;; ANSWER SECTION:
awafrewafkelwke.com.	60	IN	A	23.217.138.110

;; Query time: 18 msec
;; SERVER: ... #53( elided address is my ISP provided router)
;; WHEN: Fri Jul 15 09:55:18 PDT 2022
;; MSG SIZE  rcvd: 64

The 23.217.138.110 is basically an ad serving honey pot, the correct answer is no such domain (NXDOMAIN):

$ dig @8.8.8.8  awafrewafkelwke.com

; <<>> DiG 9.10.6 <<>> @8.8.8.8 awafrewafkelwke.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 35448
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;awafrewafkelwke.com.		IN	A

;; AUTHORITY SECTION:
com.			900	IN	SOA	a.gtld-servers.net. nstld.verisign-grs.com. 1657904107 1800 900 604800 86400

;; Query time: 194 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Jul 15 09:55:38 PDT 2022
;; MSG SIZE  rcvd: 121

Good luck, but other then allowing a custom client stack (which they have) there is no API ExoPlayer can help you with.

stevemayhew avatar Jul 15 '22 17:07 stevemayhew

Thanks @stevemayhew for more details, this is really helpful. Was surprised to know that few ISP do send bogus IP(ad serving honey pot) if it's not able to resolve hostname. If ISP blocks client control of using external DNS servers for resolving hostname and ISP are not able to resolve hostnames for some reason, we end up in irrecoverable error where host is not accessible where its neither client nor server issue !!

Lohit-Huddar avatar Jul 18 '22 05:07 Lohit-Huddar