iOS 11.3 delays creation of WKWebsiteDataStore and queues setCookie completion handler

Originator:hshamansky
Number:rdar://40100673 Date Originated:5/9/2018
Status:Open Resolved:
Product:WebKit Product Version:iOS 11.3
Classification:Bug Reproducible:Usually
 
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

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!