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

Question Catching "Curl error 28"

Discussion in 'Scripting' started by flecona, Apr 29, 2022.

  1. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    I've been trying to catch and/or hide this "Curl error 28: Operation timed out after 1000 milliseconds with 0 bytes received". I'm using UnityWebRequest and I'm able to handle a timeout but the error shows up in logs and console anyways, I've tried with both Coroutines and just iterating the UnityWebRequestAsyncOperation but I can't find where I could catch that ugly error.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3.  
    4. public class RestClientTest : MonoBehaviour
    5. {
    6.     UnityWebRequest Request;
    7.     UnityWebRequestAsyncOperation ActiveRequest;
    8.  
    9.     void Start()
    10.     {
    11.         MakeRequest();
    12.     }
    13.  
    14.     private void Update()
    15.     {
    16.         UpdateActiveRequest();
    17.     }
    18.  
    19.     private void MakeRequest()
    20.     {
    21.         Request = UnityWebRequest.Get("http://localhost:8081/api/");
    22.         ActiveRequest = Request.SendWebRequest();
    23.     }
    24.  
    25.     private void UpdateActiveRequest()
    26.     {
    27.         if (ActiveRequest.isDone)
    28.         {
    29.             Debug.Log("Request is done!");
    30.             if (Request.isNetworkError || Request.isHttpError)
    31.             {
    32.                 Debug.Log("Request has error");
    33.             }
    34.         }
    35.         else
    36.         {
    37.             Debug.Log("Request is at " +
    38.                (ActiveRequest.progress * 100f).ToString("F2") + "%");
    39.         }
    40.     }
    41. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,717
    Is that even you? I think that's just Unity editor barf... unless you think it's coming as a result of you.

    Is there any clue to be found from selecting it and looking at the callstack in the bottom of the console window?
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    This is an error Unity internal logs. You web request should come out as error, the message is logged for help (in some cases in contains some useful info).
    Your code sample does not contain timeout, yet the error says it timed out after one second, which is VERY small timeout.
     
    flecona likes this.
  4. flecona

    flecona

    Joined:
    Jun 11, 2018
    Posts:
    10
    Kurt: yeah I definitely get the error from the UnityWebRequest but when you select the error you don't get the usual info such as callstack or the line that originated the error.

    Aurimas: you are right, I forgot to add the line where I'm adding a timeout. Turns out everything works much better when I don't set a timeout even when I use an invalid or non-responsive address.

    I will continue just using everything without a timeout but it would definitely be nice if those Curl errors could be caught and hidden, I understand they can be useful but you don't always want to see them.
     
  5. akeplinger

    akeplinger

    Joined:
    Oct 26, 2008
    Posts:
    56
    Hitting this myself. I have an admin app that pings 10 other IP addresses to check status. Responses don't need to be immediate. I'm testing to see if the computers are present, a step above pinging them. The system works, but if the computer at the IP address is offline it times out and I get the Curl error.
    The error must be triggered by a separate thread because there is no information about processes. Just the error on a single line. If I don't set the timeout to a second or two the app will wait a full 30 seconds before reporting the error.
    I'm guessing that these kinds of errors just get passed through.
     
  6. IndieMarc

    IndieMarc

    Joined:
    Jan 16, 2017
    Posts:
    181

    I was trying to find something similar, I managed to hide those errors with this:


    Code (CSharp):
    1.  
    2. public static void SendRequest(UnityWebRequest request, Action<UnityWebRequest.Result> callback)
    3. {
    4.     SendRequestAsync(request, callback);
    5. }
    6.  
    7. private static async void SendRequestAsync(UnityWebRequest request, Action<UnityWebRequest.Result> callback)
    8. {
    9.     try
    10.     {
    11.         var asyncOp = request.SendWebRequest();
    12.         while (!asyncOp.isDone)
    13.             await Task.Delay(200);
    14.     }
    15.     catch (Exception) {}
    16.    
    17.     if (callback != null)
    18.         callback.Invoke(request.result);
    19. }
    20.  
     
  7. IndieMarc

    IndieMarc

    Joined:
    Jan 16, 2017
    Posts:
    181
    Ignore my previous post, it doesn't seem to work.

    Seems like it doesn't catch the errors because the SendWebRequest is async in another routine.

    Shouldn't this error be a regular log or warning? Not an error that can pause the game if the console Error Pause is on?

    Because there doesn't seem to be any way to catch it.

    Seems like a really bad design of this function. Any plan to change it?
     
    Last edited: Apr 5, 2023
  8. IndieMarc

    IndieMarc

    Joined:
    Jan 16, 2017
    Posts:
    181
    This is kinda ridiculous, but seems to solve it. It basically abort the request right before the timeout expires. I would suggest a timeout of at least 5 seconds.


    Code (CSharp):
    1. public static async Task<bool> SendRequest(UnityWebRequest request)
    2. {
    3.         int wait = 0;
    4.         int wait_max = request.timeout * 1000;
    5.         request.timeout += 1; //Add offset to make sure it abort first
    6.  
    7.         var asyncOp = request.SendWebRequest();
    8.         while (!asyncOp.isDone)
    9.         {
    10.             await Task.Delay(200);
    11.             wait += 200;
    12.             if (wait >= wait_max)
    13.                 request.Abort();
    14.         }
    15.  
    16.         return request.result == UnityWebRequest.Result.Success;
    17. }
    I would strongly suggest Unity to change this error into a log or warning in future versions.
     
    Last edited: Apr 5, 2023
  9. odysoftware

    odysoftware

    Joined:
    Jul 21, 2015
    Posts:
    84
    Yes the error really does not make any sense at all a simple warning would be just fine?!?
     
  10. princeamera07

    princeamera07

    Joined:
    Nov 3, 2021
    Posts:
    2
    my ISP blocked sites categorised as games and when iam trying to download any package it shows error