Search Unity

FIX for useless timeout implementation

Discussion in 'Addressables' started by Wawro01, Jan 21, 2020.

  1. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    44
    Currently addressables are using timeout from WebRequest which implementation is bit strange. It simply checks time against time of which request started. If the result is higher than timeout value, download will fail. So if you will download big file with small timeout time it will fail.

    This is modification better check if download is hanging or not, use it in AssetBundleResource:


    Code (CSharp):
    1.         private float m_LastUpdatedTime;
    2.         private float m_LastPercentsComplete = -1f;
    3.  
    4.         private void CheckHangingDownload()
    5.         {
    6.             UnityWebRequestAsyncOperation remoteReq = m_RequestOperation as UnityWebRequestAsyncOperation;
    7.          
    8.             if (remoteReq == null)
    9.             {
    10.                 return;
    11.             }
    12.  
    13.             var percentsComplete = remoteReq.progress;
    14.             if (!Mathf.Approximately(percentsComplete, m_LastPercentsComplete))
    15.             {
    16.                 m_LastPercentsComplete = percentsComplete;
    17.                 m_LastUpdatedTime = Time.realtimeSinceStartup;
    18.             }
    19.  
    20.             if (Time.realtimeSinceStartup - m_LastUpdatedTime > m_Options.Timeout)
    21.             {
    22.                 Debug.LogError($"Aborting hanging download {remoteReq.webRequest.url}");
    23.                 remoteReq.webRequest.Abort();
    24.                 m_LastUpdatedTime = Time.realtimeSinceStartup;
    25.                 m_LastPercentsComplete = -1;
    26.             }
    27.         }
    28.  
    29.         //change this method of original file
    30.         float PercentComplete()
    31.         {
    32.             CheckHangingDownload();
    33.             return m_RequestOperation?.progress ?? 0.0f;
    34.         }
     
  2. CameronND

    CameronND

    Joined:
    Oct 2, 2018
    Posts:
    89
    This is really useful thanks.

    One question: doesn't the Timeout value still get passed over to the UnityWebRequest class anyway? So that means that the request will just fail once it reaches a duration of the timeout? Or did you remove that part from their code?
     
  3. Wawro01

    Wawro01

    Joined:
    Apr 23, 2014
    Posts:
    44
    You are right, I forgot to mention it here. Just comment it out from
    CreateWebRequest in AssetBundleResource.