Title: [271404] trunk/Source/WebCore
Revision
271404
Author
[email protected]
Date
2021-01-12 09:00:21 -0800 (Tue, 12 Jan 2021)

Log Message

Safari Networking high % CPU when Caches/WebKit/ServiceWorkers folder not writable
https://bugs.webkit.org/show_bug.cgi?id=220220
<rdar://problem/72930195>

Reviewed by Chris Dumez.

In case writing changes in the service worker database fails, we retry once.
If it fails, we give up and will only retry writing when new changes happen.
Manually tested.

* workers/service/server/RegistrationDatabase.cpp:
(WebCore::RegistrationDatabase::pushChanges):
(WebCore::RegistrationDatabase::schedulePushChanges):
* workers/service/server/RegistrationDatabase.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271403 => 271404)


--- trunk/Source/WebCore/ChangeLog	2021-01-12 16:30:40 UTC (rev 271403)
+++ trunk/Source/WebCore/ChangeLog	2021-01-12 17:00:21 UTC (rev 271404)
@@ -1,3 +1,20 @@
+2021-01-12  Youenn Fablet  <[email protected]>
+
+        Safari Networking high % CPU when Caches/WebKit/ServiceWorkers folder not writable
+        https://bugs.webkit.org/show_bug.cgi?id=220220
+        <rdar://problem/72930195>
+
+        Reviewed by Chris Dumez.
+
+        In case writing changes in the service worker database fails, we retry once.
+        If it fails, we give up and will only retry writing when new changes happen.
+        Manually tested.
+
+        * workers/service/server/RegistrationDatabase.cpp:
+        (WebCore::RegistrationDatabase::pushChanges):
+        (WebCore::RegistrationDatabase::schedulePushChanges):
+        * workers/service/server/RegistrationDatabase.h:
+
 2021-01-12  Philippe Normand  <[email protected]>
 
         Unreviewed, workaround for GTK EnumerateDevices API test crash.

Modified: trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp (271403 => 271404)


--- trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2021-01-12 16:30:40 UTC (rev 271403)
+++ trunk/Source/WebCore/workers/service/server/RegistrationDatabase.cpp	2021-01-12 17:00:21 UTC (rev 271404)
@@ -297,12 +297,13 @@
         else
             removedRegistrations.append(keyValue.key.isolatedCopy());
     }
-    schedulePushChanges(WTFMove(updatedRegistrations), WTFMove(removedRegistrations), WTFMove(completionHandler));
+    schedulePushChanges(WTFMove(updatedRegistrations), WTFMove(removedRegistrations), ShouldRetry::Yes, WTFMove(completionHandler));
 }
 
-void RegistrationDatabase::schedulePushChanges(Vector<ServiceWorkerContextData>&& updatedRegistrations, Vector<ServiceWorkerRegistrationKey>&& removedRegistrations, CompletionHandler<void()>&& completionHandler)
+void RegistrationDatabase::schedulePushChanges(Vector<ServiceWorkerContextData>&& updatedRegistrations, Vector<ServiceWorkerRegistrationKey>&& removedRegistrations, ShouldRetry shouldRetry, CompletionHandler<void()>&& completionHandler)
 {
-    postTaskToWorkQueue([this, protectedThis = makeRef(*this), pushCounter = m_pushCounter, updatedRegistrations = WTFMove(updatedRegistrations), removedRegistrations = WTFMove(removedRegistrations), completionHandler = WTFMove(completionHandler)]() mutable {
+    auto pushCounter = shouldRetry == ShouldRetry::Yes ? m_pushCounter : 0;
+    postTaskToWorkQueue([this, protectedThis = makeRef(*this), pushCounter, updatedRegistrations = WTFMove(updatedRegistrations), removedRegistrations = WTFMove(removedRegistrations), completionHandler = WTFMove(completionHandler)]() mutable {
         bool success = doPushChanges(updatedRegistrations, removedRegistrations);
         if (success) {
             updatedRegistrations.clear();
@@ -310,8 +311,8 @@
         }
         callOnMainThread([this, protectedThis = WTFMove(protectedThis), success, pushCounter, updatedRegistrations = WTFMove(updatedRegistrations).isolatedCopy(), removedRegistrations = WTFMove(removedRegistrations).isolatedCopy(), completionHandler = WTFMove(completionHandler)]() mutable {
             if (!success && (pushCounter + 1) == m_pushCounter) {
-                // We retry writing if no other change was pushed.
-                schedulePushChanges(WTFMove(updatedRegistrations), WTFMove(removedRegistrations), WTFMove(completionHandler));
+                // We retry writing once if no other change was pushed.
+                schedulePushChanges(WTFMove(updatedRegistrations), WTFMove(removedRegistrations), ShouldRetry::No, WTFMove(completionHandler));
                 return;
             }
             if (completionHandler)

Modified: trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h (271403 => 271404)


--- trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h	2021-01-12 16:30:40 UTC (rev 271403)
+++ trunk/Source/WebCore/workers/service/server/RegistrationDatabase.h	2021-01-12 17:00:21 UTC (rev 271404)
@@ -61,7 +61,8 @@
     
     String databaseDirectoryIsolatedCopy() const { return m_databaseDirectory.isolatedCopy(); }
 
-    void schedulePushChanges(Vector<ServiceWorkerContextData>&&, Vector<ServiceWorkerRegistrationKey>&&, CompletionHandler<void()>&&);
+    enum class ShouldRetry { No, Yes };
+    void schedulePushChanges(Vector<ServiceWorkerContextData>&&, Vector<ServiceWorkerRegistrationKey>&&, ShouldRetry, CompletionHandler<void()>&&);
     void postTaskToWorkQueue(Function<void()>&&);
 
     // Methods to be run on the work queue.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to