unity network_error ai_generated true

UnityWebRequest: Timeout error: DNS resolution timed out

ID: unity/network-unitywebrequest-timeout

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2023-10-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2021.3 active
Unity 2022.3 active
Unity 2023.1 active

Root Cause

The UnityWebRequest could not resolve the hostname within the default timeout period (typically 10 seconds), often due to network configuration issues, DNS server unavailability, or incorrect URL.

generic

中文

UnityWebRequest在默认超时时间(通常10秒)内无法解析主机名,通常是由于网络配置问题、DNS服务器不可用或URL错误。

Official Documentation

https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest-timeout.html

Workarounds

  1. 90% success Check the URL for typos and ensure the hostname is reachable via a web browser or ping. If the URL is correct, configure a custom DNS server in the device's network settings or use UnityWebRequest's timeout property to a reasonable value (e.g., 15 seconds) to allow retries.
    Check the URL for typos and ensure the hostname is reachable via a web browser or ping. If the URL is correct, configure a custom DNS server in the device's network settings or use UnityWebRequest's timeout property to a reasonable value (e.g., 15 seconds) to allow retries.
  2. 85% success Implement a retry mechanism with exponential backoff: if the request fails with DNS timeout, wait 2 seconds and retry up to 3 times. Use a coroutine with yield return new WaitForSecondsRealtime(2f);
    Implement a retry mechanism with exponential backoff: if the request fails with DNS timeout, wait 2 seconds and retry up to 3 times. Use a coroutine with yield return new WaitForSecondsRealtime(2f);
  3. 80% success On mobile platforms, ensure that the app has the INTERNET permission (Android) or that network access is allowed in the Info.plist (iOS).
    On mobile platforms, ensure that the app has the INTERNET permission (Android) or that network access is allowed in the Info.plist (iOS).

中文步骤

  1. 检查URL是否有拼写错误,并确保主机名可通过浏览器或ping访问。如果URL正确,在设备的网络设置中配置自定义DNS服务器,或使用UnityWebRequest的timeout属性设置为合理值(例如15秒)以允许重试。
  2. 实现带有指数退避的重试机制:如果请求因DNS超时而失败,等待2秒并重试最多3次。使用协程配合yield return new WaitForSecondsRealtime(2f);
  3. 在移动平台上,确保应用程序具有INTERNET权限(Android)或在Info.plist中允许网络访问(iOS)。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    This only delays the error; if DNS resolution fails permanently, the request will eventually time out anyway. It does not fix the underlying DNS issue.

  2. 85% fail

    IP addresses can change, and many services require hostname-based virtual hosting. This is not a scalable or reliable fix.

  3. 95% fail

    The protocol does not affect DNS resolution; the error occurs before the HTTP handshake. This change is irrelevant.