Search Unity

Downloading large files (5~20MB) with HttpClient hangs

Discussion in 'iOS and tvOS' started by heffendy, Aug 18, 2018.

  1. heffendy

    heffendy

    Joined:
    Aug 3, 2018
    Posts:
    14
    Hi there,

    I'm hitting a very peculiar HttpClient issue on iOS (it does not repro on Unity Editor nor on WSA) when downloading larger files (5~20MB).

    The scenario is that I'm trying to download some files from my OneDrive using the Microsoft Graph APIs:

    Code (CSharp):
    1.  
    2. using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, $"/me/drive/items/{itemId}/content"))
    3. {
    4.     request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
    5.     using (HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
    6.     {
    7.             httpResponseMessage.EnsureSuccessStatusCode();
    8.             byte[] buffer = await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false); <--- 'Hangs here'
    9.             // Do work
    10.     }
    11. }
    12.  
    This works as expected for smaller files (<100KB) but I observe that the read calls never complete reliability for larger files. In the cases it doesn't work, the call to read the content of the response simply never returns.

    From looking at both Instruments and Fiddler, I see that the download actually starts but would then suddenly stop and not complete.

    I looked through some related HttpClient 'hang' posts (not disposing correctly, not using async/aawait correctly, etc) and I don't think those are the root cause here.

    I verified that this does not appear to be an issue with UnityWebRequest.

    Curious if anyone has insights what's going on here. Is there anything with the iOS platform or IL2CPP that might explain this (assuming this isn't a mono issue since it works just fine on the Editor).

    This is on Unity2017.4.2f2 targeting iOS 11 on an iPhone 8 running both iOS 11.0.3 and iOS 12 beta 6.

    Thanks!
     
    Last edited: Aug 18, 2018