UIWebView dropping connections

Originator:mikegbro
Number:rdar://39508158 Date Originated:4/17/2018
Status:Open Resolved:
Product:iOS SDK Product Version:11.3
Classification:UI/Usability Reproducible:Always
 
## Summary
Starting in iOS 11.3 when an application is backgrounded and a UIWebView is loading a URL, the network connection is terminated immediately. This was not the case in previous versions of iOS < 11.3. In previous versions the request would remain connected in the background as the user went on to another application and later returned back into the starting application.

This is a business impacting issue for two factor authentication providers where long lived connections are a requirement. They’re used to maintaining a connection while the user confirms their second factor of authentication. For example the Outlook mail app may hold open a connection to Duo Security’s service while the user backgrounds the app, goes into Duo Mobile, and approves the second factor authentication. This bug introduced in 11.3 prevents that workflow. It should be noted that this is not how it works with SFSafariViewController or WKWebViews.

## Steps to Reproduce
1. Start a long poll connection within an application in a UIWebView
2. Background the application before that request has yet to finish
3. Wait until the request should normal finish
4. Resume the application from #1
5. In iOS 11.3 observe the request was terminated as soon as the app was backgrounded and the connection had been dropped. 

I’ve attached a sample project with two parts. One is a simple python server that serves up a webpage 5 seconds after it’s requested at http://localhost:8000. The second part is a simple iOS application that opens up a UIWebView (among other options) and attempt to load this URL. To demo this functionality you need 2 iOS devices, one on 11.3 and one on an earlier version of iOS and follow the steps below.

1. Start the included simple python server in ./PythonServer with `python server.py`
2. Find the public IP of a machine running the sample python server (The IP that can be hit by an external iOS device on the same network) 
3. Open up the included code project “ConnectionBugDemo.xcodeproj”
4. In ViewController.m change urlString to be equal to @“http://<local.IP>:8000”
5. Launch the application on either an iOS 11.3 device or an older OS to see varying behaviors
6. Tap “Load UIWebView”
7. Background the application before the view loads (5 seconds)
8. Foreground the application
9. Notice on 11.3 the UIWebView drops the connection and never loads. However pre-11.3 it does load. The python server reports a broken pipe error as well on 11.3.
10. The sample also shows WKWebView and SFSafariViewController work as expected.

## Expected Results
In versions of iOS before 11.3 the UIWebView would keep the connection open as the user backgrounded the application. 

## Actual Results
In iOS 11.3 the long poll connection in the UIWebView is dropped. 

## Version/Build
iOS 11.3 (On device, not reproducible in simulators)

## Configuration
Running demos on macOS with python 2 and on devices iOS 11.3 and iOS 11.0.1

Comments

Behavior change for iOS 11.4.1

Hi, Just tested the same issue on ios 11.4.1 device, the testing shows when putting the app into background, the uiWebView connection does not dropped as 11.3 ios testing. And later when the app goes back to foreground, the uiwebview's request will get the server response.

Fiddler shows when app goes to foreground, a new request was sent from device to server with the same request url as the original uiwebview request, but this new request is transparent to client app. When server sends the response to device for the first request, the response is ignored be device, the uiwebview did not receive it. When server sends the response for the second request, this response will return to the UIWebView's original request (i.e. first request).

Just want to know whether others also experienced the same behavior.

Thanks Jonathan Thanks Jonathan

By jonathanli2000 at Aug. 29, 2018, 8:55 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!