Skip to content

HTTP requests return null after a network change on iOS #167

@GSRicky

Description

@GSRicky

On iOS, if the network connection type changes while the app is in the background, after returning to the foreground, new HTTP requests will fail (after a timeout) with a null response even though an internet connection is available.

Environment:

  • Unity: 2020.3.19f1
  • BestHTTP: 2.5.2 (issue also reproduced on 2.8.3 for testing).
  • iOS: all OS versions seem to be affected

100% Issue Reproduction Method:

  1. Send HTTP requests using BestHTTP
  2. Wait for all requests to receive their responses (all successful
  3. Put the iOS app into the background to access the device’s networking setting
  4. Switch between mobile data/WiFi (enabling one and disabling the other
  5. Wait a few seconds (wait for the device’s connection to the internet to be re-established
  6. Return the app to the foreground
  7. Send HTTP requests using BestHTTP
  8. (ISSUE) All HTTP requests fail (timeout) with a null response.
  • Note: The above case cannot be reproduced if I substitute the BestHTTP requests with UnityWebRequests of the same configuration.

Details:

  • This issue may be a duplicate of #164 but that issue is not explained in detail.
  • The issue is 100% reproducible when following the above scenario though we also have several other known issue cases such as:
    • Changing between WiFi and a Hotspot by enabling and disabling the hotspot on a paired device
    • Exiting the range of a WiFi adapter and having the device automatically connect to mobile data
  • The issue only occurs on iOS, we are not aware of an issue on Android devices. We believe all iOS versions are affected.
  • If we switch out BestHTTP with UnityWebRequest the issue cannot be reproduced in any scenario.
  • Our HTTP requests already include the “connection close” header (though changing this did not affect the outcome)
  • Our retries are set to 0 (though we have also tested with 5 and this had no effect on the outcome)
  • We are using HTTP/2
  • The keep-alive header does not affect this issue (as expected on HTTP/2).

Known Workarounds:

  • If we call HTTPManager.AbortAll() when the app executes OnApplicationPause as it enters background, the above case is not reproduced, however, this solution cannot be used to resolve the related issues where the app does not enter the background state.
  • If we wait 90~120s after the initial successful web requests are complete and then run our test, the issues are not reproduced (we are not sure of the exact timing as our scenario needs to allow the network to reconnect and this timing is inconsistent).
  • We know a large number of our users have been affected by this issue so we have disabled BestHTTP for our network requests on iOS and have reverted to UnityWebRequest as a temporary solution. This change has resolved all network handover issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions