Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Error on internet reconnect - Curl error 56

Discussion in 'Editor & General Support' started by cmersereau, Apr 8, 2022.

  1. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    I am testing internet connectivity logic for my project. After internet is disconnected, we wait until it is reconnected to send any requests that have gotten backed up. However, we occasionally get this error when we try to send requests immediately after we detect that the internet is reconnected:

    error: Curl error 56: Receiving data failed with unitytls error code 1048578

    I have searched the forums for this error, but most topics are for crashing errors and other known bugs. That's not really what we are experiencing. It seems to be purely connected to the internet connection being reestablished. I can't say for sure, but it seems like it could be a race condition between the device properly securing it's connection before requests are sent out.

    My current solution is to delay the requests being sent for a half second to give the device more time to secure it's connection, but that is under the assumption that this is happening due to a race condition.

    Is there any helpful info that I'm missing or better solutions to this problem?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    What type of requests are you sending? Please share your code.
     
  3. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    Code (CSharp):
    1. for (var i = 0; i < RequestQueue.Count; i++)
    2.             {
    3.                 var queuedRequest = RequestQueue[i];
    4.  
    5.                 using (var freshRequest = StellaServerCommunication.CreateRequest(
    6.                     queuedRequest.Method,
    7.                     queuedRequest.Url,
    8.                     queuedRequest.SerializedData))
    9.                 {
    10.                     var response =
    11.                         await StellaServerCommunication.MakeUserRequest(freshRequest, null, Instance.LogTag(), true);
    12.                  
    13.                     if (response.Error?.Message.Equals(StellaServerCommunication.INTERNET_NOT_CONNECTED) ?? false)
    14.                     {
    15.                         StellaLogger.LogInfo($"request {i} has detected internet not connected during sync process", Instance);
    16.                         break;
    17.                     }
    18.  
    19.                     // on an error, try one additional time
    20.                     if (response.Error != null)
    21.                     {
    22.                         var requestCopy = freshRequest.MakeCopy();
    23.                         var retryResponse =
    24.                             await StellaServerCommunication.MakeUserRequest(requestCopy,
    25.                                 null,
    26.                                 Instance.LogTag());
    27.  
    28.                         // On the second attempt, treat requests that are successful or errors
    29.                         // as being resolved. Only give special logic to another loss of internet
    30.                         if (retryResponse.Error?.Message.Equals(StellaServerCommunication.INTERNET_NOT_CONNECTED) ?? false)
    31.                         {
    32.                             break;
    33.                         }
    34.                     }
    35.                  
    36.                     resolvedRequests.Add(queuedRequest);
    37.                 }
    38.             }
    This is the loop that attempts to send any queued requests. The function
    StellaServerCommunication.CreateRequest
    takes the relevant parameters to make a new request since a UWR cannot be resent. My most common test case is a Post request that is sending data to an event service.

    The code that actually sends the request is this:
    Code (CSharp):
    1. private static async Task<bool> SendRequestWithInternetCheck(UnityWebRequest request,
    2.             string testUrl, RequestArgs args, string callerName, bool queuedRequest)
    3.         {
    4.             if (!Stella.ConnectivityManager.PerformConnectionTest())
    5.             {
    6.                 StellaLogger.LogDebug("No Internet Connection Detected", LogTag, callerName);
    7.              
    8.                 if (args?.QueueRequest ?? false)
    9.                 {
    10.                     Stella.ConnectivityManager.AddRequestToQueue(request);
    11.                 }
    12.  
    13.                 return false;
    14.             }
    15.  
    16.             if (!queuedRequest && GeneralSettings.NewRequestsWaitForQueue)
    17.             {
    18.                 while (Stella.ConnectivityManager.IsSyncingTasks)
    19.                 {
    20.                     await Task.Delay(100);
    21.                 }
    22.             }
    23.  
    24.             var ao = request.SendWebRequest();
    25.             args?.ProgressCallback?.Invoke(ao);
    26.             await ao;
    27.  
    28.             var cannotResolveMessageLower = "cannot resolve destination host";
    29.  
    30.             if (request.error?.ToLower().Equals(cannotResolveMessageLower) ?? false)
    31.             {
    32.                 if (string.IsNullOrEmpty(testUrl))
    33.                 {
    34.                     return false;
    35.                 }
    36.  
    37.                 var pingRequest = UnityWebRequest.Get(testUrl);
    38.                 await pingRequest.SendWebRequest();
    39.  
    40.                 if (pingRequest.error?.ToLower().Equals(cannotResolveMessageLower) ?? false)
    41.                 {
    42.                     StellaLogger.LogDebug($"cannot resolve destination host detected for ping to {testUrl}", LogTag, callerName);
    43.                     return false;
    44.                 }
    45.             }
    46.  
    47.             return true;
    48.         }
     
  4. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    I'll just reiterate that this issue is inconsistent. Happens maybe a quarter of the time.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Sorry, I am not familiar with StellaServerCommunication.CreateRequest . Is that an asset you have purchased?
     
  6. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    It's one of our own scripts. It doesn't do anything special, just creates a new UWR using the necessary info. It just made this part of the code cleaner and easier to read to put it in a method somewhere else.