iOS 11.3 delays creation of WKWebsiteDataStore and queues setCookie completion handler

Originator:huw.rowlands
Number:rdar://42522805 Date Originated:24-Jul-2018 10:29 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 11.3
Classification:Security Reproducible:Always
 
Summary:
This is a duplicate of radar #40100673

We have the following flow in our app: If navigating to a particular URL in a WKWebView that requires a cookie, cancel the navigation, set a cookie, and in the cookie setter's completion block, load the original URL in the web view.

However, new behavior added by https://github.com/WebKit/webkit/commit/d9d6e5c82c4a74cd573f3f119f166ffcee477b04 delays the creation of the WKWebsiteDataStore such that the completion block is queued until "necessary", and WebKit never actually considers its creation "necessary" since we only load the URL in the completion block. It's essentially a deadlock.

Here's sample code:
```
if (@available(iOS 11.0, *)) {
        [webView.configuration.websiteDataStore.httpCookieStore setCookie:cookie
                                                        completionHandler:^{
            [webView loadRequest:request];
        }];
}
```

This was caused by rdar://problem/33164453 (see also https://bugs.webkit.org/show_bug.cgi?id=176551)

Steps to Reproduce:
Cancel web view navigation, set a cookie with a completion handler that loads the original (canceled) URL. Take no other action on the web view.

Expected Results:
The cookie is set and the completion handler is called.

Actual Results:
The cookie is not set (and the completion handler is not called) until another action is taken on the WKWebView that requires the WKWebsiteDataStore to be initialized.

Version/Build:
Issue affects iOS 11.3+ only. Rarely reproduces on simulator; frequently but not always reproduces on device.

Configuration:
iPhone X 11.3


Steps to Reproduce:
 

Expected Results:
 

Actual Results:
 

Version:
iOS 11.3

Notes:

Comments


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!