In my enterprise app I need to clean out the cookies of the WKWebviews to keep a clean session. Since we migrated to WKWebviews from UIWebview we have seen this crash quite often. Here is the stack trace
Crashed: com.apple.CFNetwork.LoaderQ
0 libobjc.A.dylib 0x1a6e72ed0 objc_retain + 16
1 CFNetwork 0x19268b3a8 _CFHTTPCookieStorageFlushCookieStores + 11724
2 CFNetwork 0x192691f5c _CFHTTPCookieStorageFlushCookieStores + 39296
3 CFNetwork 0x19268b220 _CFHTTPCookieStorageFlushCookieStores + 11332
4 CFNetwork 0x19268a44c _CFHTTPCookieStorageFlushCookieStores + 7792
5 CFNetwork 0x1926895bc _CFHTTPCookieStorageFlushCookieStores + 4064
6 CFNetwork 0x1926d97f4 _CFHTTPServerResponseEnqueue + 16388
7 CFNetwork 0x1926d8ca0 _CFHTTPServerResponseEnqueue + 13488
8 CFNetwork 0x1924e65a0 (Missing)
9 CFNetwork 0x19262a8f4 _CFStreamErrorFromCFError + 413612
10 CFNetwork 0x19262a588 _CFStreamErrorFromCFError + 412736
11 CFNetwork 0x1926824a8 _CFNetworkSetATSContext + 97796
12 CFNetwork 0x19267f9ac _CFNetworkSetATSContext + 86792
13 CFNetwork 0x192730efc _CFURLStorageSessionCopyCache + 67584
14 libdispatch.dylib 0x191ad824c _dispatch_call_block_and_release + 32
15 libdispatch.dylib 0x191ad9db0 _dispatch_client_callout + 20
16 libdispatch.dylib 0x191ae110c _dispatch_lane_serial_drain + 580
17 libdispatch.dylib 0x191ae1c90 _dispatch_lane_invoke + 460
18 libdispatch.dylib 0x191ae2e60 _dispatch_workloop_invoke + 1588
19 libdispatch.dylib 0x191aebd78 _dispatch_workloop_worker_thread + 708
20 libsystem_pthread.dylib 0x1dd6b7804 _pthread_wqthread + 276
21 libsystem_pthread.dylib 0x1dd6be75c start_wqthread + 8
This portion of the app is older and written in Objc
We started with this
[[NSHTTPCookieStorage sharedHTTPCookieStorage] removeCookiesSinceDate:[NSDate distantPast]];
but have since removed it in a test.
We are currently using this
[self.sharedDatastore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> * _Nonnull cookies) {
for (NSHTTPCookie *cookie in cookies){
[self.sharedDatastore.httpCookieStore deleteCookie:cookie completionHandler:^{
//NSLog(@"^Deleted Cookie %@", cookie.name);
}];
}
}];
We keep references to a shared data pool, data store and urlSession which is used to instantiate new WKWebviews so they have the same cookie store to work from.
@property (nonatomic, strong) WKProcessPool *sharedPool;
@property (nonatomic, strong) WKWebsiteDataStore *sharedDatastore;
@property (nonatomic, strong) NSURLSession *sharedSession;
I guess I have 2 questions. Is this cookie issue a known issue and is there a better way to keep the shared cookie and session info letting the other wkwebviews know about it? This used to work flawlessly with the old UIWebviews..:(
Crashed: com.apple.CFNetwork.LoaderQ
0 libobjc.A.dylib 0x1a6e72ed0 objc_retain + 16
1 CFNetwork 0x19268b3a8 _CFHTTPCookieStorageFlushCookieStores + 11724
2 CFNetwork 0x192691f5c _CFHTTPCookieStorageFlushCookieStores + 39296
3 CFNetwork 0x19268b220 _CFHTTPCookieStorageFlushCookieStores + 11332
4 CFNetwork 0x19268a44c _CFHTTPCookieStorageFlushCookieStores + 7792
5 CFNetwork 0x1926895bc _CFHTTPCookieStorageFlushCookieStores + 4064
6 CFNetwork 0x1926d97f4 _CFHTTPServerResponseEnqueue + 16388
7 CFNetwork 0x1926d8ca0 _CFHTTPServerResponseEnqueue + 13488
8 CFNetwork 0x1924e65a0 (Missing)
9 CFNetwork 0x19262a8f4 _CFStreamErrorFromCFError + 413612
10 CFNetwork 0x19262a588 _CFStreamErrorFromCFError + 412736
11 CFNetwork 0x1926824a8 _CFNetworkSetATSContext + 97796
12 CFNetwork 0x19267f9ac _CFNetworkSetATSContext + 86792
13 CFNetwork 0x192730efc _CFURLStorageSessionCopyCache + 67584
14 libdispatch.dylib 0x191ad824c _dispatch_call_block_and_release + 32
15 libdispatch.dylib 0x191ad9db0 _dispatch_client_callout + 20
16 libdispatch.dylib 0x191ae110c _dispatch_lane_serial_drain + 580
17 libdispatch.dylib 0x191ae1c90 _dispatch_lane_invoke + 460
18 libdispatch.dylib 0x191ae2e60 _dispatch_workloop_invoke + 1588
19 libdispatch.dylib 0x191aebd78 _dispatch_workloop_worker_thread + 708
20 libsystem_pthread.dylib 0x1dd6b7804 _pthread_wqthread + 276
21 libsystem_pthread.dylib 0x1dd6be75c start_wqthread + 8
This portion of the app is older and written in Objc
We started with this
[[NSHTTPCookieStorage sharedHTTPCookieStorage] removeCookiesSinceDate:[NSDate distantPast]];
but have since removed it in a test.
We are currently using this
[self.sharedDatastore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> * _Nonnull cookies) {
for (NSHTTPCookie *cookie in cookies){
[self.sharedDatastore.httpCookieStore deleteCookie:cookie completionHandler:^{
//NSLog(@"^Deleted Cookie %@", cookie.name);
}];
}
}];
We keep references to a shared data pool, data store and urlSession which is used to instantiate new WKWebviews so they have the same cookie store to work from.
@property (nonatomic, strong) WKProcessPool *sharedPool;
@property (nonatomic, strong) WKWebsiteDataStore *sharedDatastore;
@property (nonatomic, strong) NSURLSession *sharedSession;
I guess I have 2 questions. Is this cookie issue a known issue and is there a better way to keep the shared cookie and session info letting the other wkwebviews know about it? This used to work flawlessly with the old UIWebviews..:(