Score:0

How Iphone choose IP address when it gets multiple IP address in dns response?

in flag

I am trying to understand how Iphone decides which IP address to use from 2 IP addresses returned in dns response in this specific scenario below.

Scenario is like this:

1- Iphone sends dns query for an Arecord like "bsf.mncxx.mccxx.pub.3gppnetwork.org" and gets 2 IP addresses in the response.

2- Iphone sends GET requests to one of the IP address to authenticate itself (not important which BSF IP selected at this step)

3- BSF returns 401 Unauthorized with authentication challenge

4- Iphone calculates the response and sends it in 2nd GET request.

Problem starts here. Iphone selects BSF randomly here. The expectation is to send this 2nd GET(with calculated response) to the same BSF in step2. All other phones (Samsung, Huawei, Sony etc) sends it to BSF in step2. But it seems Iphone just randomly selects. If other BSF is selected, authentication fails.

As a workaround, we configured BSF to send Connection:keep-alive in http 401 response, but unfortunately it didn't help. Iphone still selects it randomly.

Here in our setup, BSF IP addresses are in close subnets (BSF1 = 172.31.59.165, BSF2= 172.31.59.181)

It's very strange that, in another setup (not exactly same BSFs with ours but http request and responses similar) same Iphone always selects the same BSF in step2 and step4 (BSF1=10.216.138.78, BSF2= 10.210.149.79). If it selects BSF1 in step2, continues with BSF1 in step4. Same for BSF2.

Is it possible that Iphone checks subnets during decision? Any other guess or suggestion will be highly appreciated.

Thanks White

Michael Hampton avatar
cz flag
It is valid to connect to either IP address on subsequent requests. Your application needs to be able to handle this.
White11 avatar
in flag
Thanks, you may be right but it does not explain why the same iphone behaves different in 2 different setups. Its just very easy to face the problem in first setup, but in the second setup it is impossible to produce it. I am not talking about a few calls, thousands of calls and all are successful.
us flag
It isn't worth the time to wonder why iPhone works like it does. It works according to the DNS specification, and the only sensible way forward is to fix the application.
in flag
You have 50% chance of using the same server. Some implementations might reuse last working first, others might try the different result first to help balance, it's still is around 1/4 - 1/3 be chance of using different results. If you have different records you must expect it to chang on EVERY request.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.