Title: [203094] trunk/Source/WebKit2
- Revision
- 203094
- Author
- [email protected]
- Date
- 2016-07-11 16:29:23 -0700 (Mon, 11 Jul 2016)
Log Message
[WK2][iOS] Intermittent crash in [UIApplication beginBackgroundTaskWithName] expiration handler
https://bugs.webkit.org/show_bug.cgi?id=159648
<rdar://problem/27219361>
Reviewed by Anders Carlsson.
We see an intermittent crash in [UIApplication beginBackgroundTaskWithName] expiration handler.
>From the traces, we noticed the expiration handler can get called on a non-main thread under
certain conditions, which our code is designed to deal with.
In particular, we get called on a non-main thread when UIKit fails to acquire the assertion.
Update our expiration handler to always notify the clients on the main thread.
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (203093 => 203094)
--- trunk/Source/WebKit2/ChangeLog 2016-07-11 23:25:40 UTC (rev 203093)
+++ trunk/Source/WebKit2/ChangeLog 2016-07-11 23:29:23 UTC (rev 203094)
@@ -1,3 +1,21 @@
+2016-07-11 Chris Dumez <[email protected]>
+
+ [WK2][iOS] Intermittent crash in [UIApplication beginBackgroundTaskWithName] expiration handler
+ https://bugs.webkit.org/show_bug.cgi?id=159648
+ <rdar://problem/27219361>
+
+ Reviewed by Anders Carlsson.
+
+ We see an intermittent crash in [UIApplication beginBackgroundTaskWithName] expiration handler.
+ From the traces, we noticed the expiration handler can get called on a non-main thread under
+ certain conditions, which our code is designed to deal with.
+
+ In particular, we get called on a non-main thread when UIKit fails to acquire the assertion.
+ Update our expiration handler to always notify the clients on the main thread.
+
+ * UIProcess/ios/ProcessAssertionIOS.mm:
+ (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
+
2016-07-11 Dan Bernstein <[email protected]>
Tried to fix the macOS build.
Modified: trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm (203093 => 203094)
--- trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm 2016-07-11 23:25:40 UTC (rev 203093)
+++ trunk/Source/WebKit2/UIProcess/ios/ProcessAssertionIOS.mm 2016-07-11 23:29:23 UTC (rev 203094)
@@ -31,6 +31,7 @@
#import "AssertionServicesSPI.h"
#import <UIKit/UIApplication.h>
#import <wtf/HashSet.h>
+#import <wtf/RunLoop.h>
#import <wtf/Vector.h>
#if !PLATFORM(IOS_SIMULATOR)
@@ -91,15 +92,28 @@
_clients.remove(&client);
}
+- (void)_notifyClientsOfImminentSuspension
+{
+ ASSERT(RunLoop::isMain());
+ Vector<ProcessAssertionClient*> clientsToNotify;
+ copyToVector(_clients, clientsToNotify);
+ for (auto* client : clientsToNotify)
+ client->assertionWillExpireImminently();
+}
+
- (void)_updateBackgroundTask
{
if (_needsToRunInBackgroundCount && _backgroundTask == UIBackgroundTaskInvalid) {
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.ProcessAssertion" expirationHandler:^{
- NSLog(@"Background task expired while holding WebKit ProcessAssertion.");
- Vector<ProcessAssertionClient*> clientsToNotify;
- copyToVector(_clients, clientsToNotify);
- for (auto* client : clientsToNotify)
- client->assertionWillExpireImminently();
+ LOG_ALWAYS_ERROR(true, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d).", RunLoop::isMain());
+ // The expiration handler gets called on a non-main thread when the underlying assertion could not be taken (rdar://problem/27278419).
+ if (RunLoop::isMain())
+ [self _notifyClientsOfImminentSuspension];
+ else {
+ dispatch_sync(dispatch_get_main_queue(), ^{
+ [self _notifyClientsOfImminentSuspension];
+ });
+ }
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
_backgroundTask = UIBackgroundTaskInvalid;
}];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes