Search Unity

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

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Are there any caveats when using HttpClient with IL2CPP?

Discussion in 'iOS and tvOS' started by j-borden, Aug 7, 2015.

  1. j-borden

    j-borden

    Joined:
    Mar 3, 2015
    Posts:
    21
    About 50% of the time, the library I am working on freezes on a certain network call that is making use of HttpClient.SendAsync(). I am working on getting a smaller test case to submit, but this problem only happens on Unity iOS (Mono2x has different problems with EXC_BAD_ACCESS at the moment so cannot confirm if it works there or not, but on Standalone this works fine). When I pause to get the thread stack traces I notice a similar pattern each time:

    1) There are two threads labeled Async I/O Thread that are both blocking on socket receive functionality.
    2) I have one thread of my own blocking on receiving data from a hanging HTTP connection (this is on purpose)
    3) No other threads go through any of my code, which suggests that the problem is between SendAsync and ContinueWith

    Before I get an actual reproduction case ready, is there anything anyone can think of that could be causing this? Does IL2CPP hard limit to two HTTP connections the way that Mono does by default? Can this be altered?

    Thanks!
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,011
    @j.borden

    I'm not aware of what might be causing this, and I don't think that it is something we've seen yet with IL2CPP. The behavior of IL2CPP should be the same as it is with Mono in this case, and IL2CPP does not expose any way to modify it.
     
  3. xmedeko

    xmedeko

    Joined:
    Jun 6, 2018
    Posts:
    23
    I have probably similar issue with IL2CPP and Unity 2019.1.0f2. Some await HttpClient.SendAsync() works and some get stuck. Probably the problem is when await HttpClient.SendAsync() is called from non-main thread, i.e. without Unity SynchronizationContext. The process (window) cannot be closed, probably waiting for SendAsync() to finish.
    I'll try to isolate the issue to some example project.
     
    JoshPeterson likes this.
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,011
    Please submit a bug report if you can isolate this, thanks!
     
  5. xmedeko

    xmedeko

    Joined:
    Jun 6, 2018
    Posts:
    23
    JoshPeterson likes this.
  6. xmedeko

    xmedeko

    Joined:
    Jun 6, 2018
    Posts:
    23
    Another problem is, that the
    HttpClient
    ignores Windows proxy settings. I have found a workaround for the Mono build:

    Code (CSharp):
    1. var handler = new HttpClientHandler();
    2. handler.UseDefaultCredentials = true;
    3. handler.Proxy = System.Net.WebRequest.DefaultWebProxy;
    4. var client = new HttpClient(handler);
    But it does not work for IL2CPP! I have filled a bug https://fogbugz.unity3d.com/default.asp?1156595_buha3p1v4iq7vpv9
     
  7. xmedeko

    xmedeko

    Joined:
    Jun 6, 2018
    Posts:
    23
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,011
    Thanks for the bugs, we will investigate them.
     
unityunity