Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SocketException with GetNetworkTime on cell #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickfourtimes
Copy link

@nickfourtimes nickfourtimes commented Aug 7, 2023

During testing, we found that running Time.GetNetworkTime on an iPhone XR (iOS 16.5.1c), on cellular data, caused a SocketException. After thorough investigation with Unity support, it was determined that ineligible (IPv6) addresses were being returned via Dns.GetHostEntryAsync; the present change addresses this.

During testing, we found that running GetNetworkTime on an iPhone XR (iOS 16.5.1c), on cellular data, caused a SocketException in Time.GetNetworkTime. After thorough investigation with Unity support, it was determined that ineligible (IPv6) addresses were being returned via Dns.GetHostEntryAsync; the present change addresses this.
@nickfourtimes
Copy link
Author

To provide more detail: I'd noticed the SocketException while debugging an issue with Time.GetNetworkTime, and escalated the issue with our contacts at Unity support. After some thorough investigation, these were their findings:


After a lot of debugging I found the problem, it turns out that over cellular data Dns.GetHostEntryAsync includes IPv6 in the results array, while over wifi it only lists IPv4 ones, so it ended up attempting to create an endpoint with an IPv6 address.

When converting the endpoint to string I got the following values:

In its documentation I can see Dns.GetHostEntryAsync filters IPv6 addresses when the requesting device doesn't have IPv6 installed. I suspect some servers from the cellular data chain connection act as proxy affecting the dns lookup; I'm not entirely sure that's the reason, but I managed to solve the issue by ignoring the IPv6 addresses.

The original code takes the object 0 from the IP results array from Dns.GetHostEntryAsync. I did some code for iterating over the array and use the first IPv4 address, now I can get a valid IP for creating a valid endpoint, thus opening the socket correctly:

[Listing from Apple.Core/Runtime/Time.cs, as included in this pull request]

jared-marsau added a commit that referenced this pull request Dec 8, 2023
ceceomer pushed a commit to ceceomer/unityplugins that referenced this pull request Apr 6, 2024
DodgyTim pushed a commit to dodgy-ltd/apple-unityplugins that referenced this pull request Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants