Title: [224452] trunk/Source/WebCore
Revision
224452
Author
cdu...@apple.com
Date
2017-11-03 18:57:57 -0700 (Fri, 03 Nov 2017)

Log Message

[iOS-WK1] Fix thread safety issue in WebSQLiteDatabaseTrackerClient
https://bugs.webkit.org/show_bug.cgi?id=179190

Reviewed by David Kilzer.

WebSQLiteDatabaseTrackerClient and its HystererisActivity member are constructed on the UIThread. The
HystererisActivity activity also fires on the UIThread, which means that WebSQLiteDatabaseTrackerClient::hysteresisUpdated()
gets called on the UIThread.

However, the code in WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction() / WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
uses callOnMainThread() before calling methods on the HysteresisActivity. callOnMainThread() dispatches to the WebThread on WK1 iOS, which
would lead to crashes when calling methods of the HystererisActivity object:
*** -[CFRunLoopTimer respondsToSelector:]: message sent to deallocated instance 0x1c0b6a500

To address the issue, we now dispatch_async() to the main queue in willBeginFirstTransaction() / didFinishLastTransaction()
instead of using callOnMainThread(). I also added assertions to catch issues like these.

* platform/ios/WebSQLiteDatabaseTrackerClient.mm:
(WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction):
(WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction):
(WebCore::WebSQLiteDatabaseTrackerClient::hysteresisUpdated):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224451 => 224452)


--- trunk/Source/WebCore/ChangeLog	2017-11-04 01:14:33 UTC (rev 224451)
+++ trunk/Source/WebCore/ChangeLog	2017-11-04 01:57:57 UTC (rev 224452)
@@ -1,3 +1,27 @@
+2017-11-03  Chris Dumez  <cdu...@apple.com>
+
+        [iOS-WK1] Fix thread safety issue in WebSQLiteDatabaseTrackerClient
+        https://bugs.webkit.org/show_bug.cgi?id=179190
+
+        Reviewed by David Kilzer.
+
+        WebSQLiteDatabaseTrackerClient and its HystererisActivity member are constructed on the UIThread. The
+        HystererisActivity activity also fires on the UIThread, which means that WebSQLiteDatabaseTrackerClient::hysteresisUpdated()
+        gets called on the UIThread.
+
+        However, the code in WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction() / WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
+        uses callOnMainThread() before calling methods on the HysteresisActivity. callOnMainThread() dispatches to the WebThread on WK1 iOS, which
+        would lead to crashes when calling methods of the HystererisActivity object:
+        *** -[CFRunLoopTimer respondsToSelector:]: message sent to deallocated instance 0x1c0b6a500
+
+        To address the issue, we now dispatch_async() to the main queue in willBeginFirstTransaction() / didFinishLastTransaction()
+        instead of using callOnMainThread(). I also added assertions to catch issues like these.
+
+        * platform/ios/WebSQLiteDatabaseTrackerClient.mm:
+        (WebCore::WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction):
+        (WebCore::WebSQLiteDatabaseTrackerClient::didFinishLastTransaction):
+        (WebCore::WebSQLiteDatabaseTrackerClient::hysteresisUpdated):
+
 2017-11-03  Ryosuke Niwa  <rn...@webkit.org>
 
         ASSERTION FAILED: NoEventDispatchAssertion::InMainThread::isEventAllowed() || (frameView && frameView->isInChildFrameWithFrameFlattening())

Modified: trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm (224451 => 224452)


--- trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	2017-11-04 01:14:33 UTC (rev 224451)
+++ trunk/Source/WebCore/platform/ios/WebSQLiteDatabaseTrackerClient.mm	2017-11-04 01:57:57 UTC (rev 224452)
@@ -52,6 +52,7 @@
 WebSQLiteDatabaseTrackerClient::WebSQLiteDatabaseTrackerClient()
     : m_hysteresis([this](PAL::HysteresisState state) { hysteresisUpdated(state); }, hysteresisDuration)
 {
+    ASSERT(pthread_main_np());
 }
 
 WebSQLiteDatabaseTrackerClient::~WebSQLiteDatabaseTrackerClient()
@@ -60,7 +61,7 @@
 
 void WebSQLiteDatabaseTrackerClient::willBeginFirstTransaction()
 {
-    callOnMainThread([this] {
+    dispatch_async(dispatch_get_main_queue(), [this] {
         m_hysteresis.start();
     });
 }
@@ -67,7 +68,7 @@
 
 void WebSQLiteDatabaseTrackerClient::didFinishLastTransaction()
 {
-    callOnMainThread([this] {
+    dispatch_async(dispatch_get_main_queue(), [this] {
         m_hysteresis.stop();
     });
 }
@@ -74,6 +75,7 @@
 
 void WebSQLiteDatabaseTrackerClient::hysteresisUpdated(PAL::HysteresisState state)
 {
+    ASSERT(pthread_main_np());
     if (state == PAL::HysteresisState::Started)
         [WebDatabaseTransactionBackgroundTaskController startBackgroundTask];
     else
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to