Scheduling a service worker job in server should wait for finishing the registration import
https://bugs.webkit.org/show_bug.cgi?id=202975

Reviewed by Chris Dumez.

* WebProcess/Storage/WebSWClientConnection.cpp:
(WebKit::WebSWClientConnection::scheduleJobInServer):
We should not schedule a job until the registrations are fully imported.
Covered by ServiceWorkerBasic API test flakily hitting debug asserts.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251152 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog
index 12cc035..ed7f729 100644
--- a/Source/WebKit/ChangeLog
+++ b/Source/WebKit/ChangeLog
@@ -1,3 +1,15 @@
+2019-10-15  youenn fablet  <youenn@apple.com>
+
+        Scheduling a service worker job in server should wait for finishing the registration import
+        https://bugs.webkit.org/show_bug.cgi?id=202975
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+        (WebKit::WebSWClientConnection::scheduleJobInServer):
+        We should not schedule a job until the registrations are fully imported.
+        Covered by ServiceWorkerBasic API test flakily hitting debug asserts.
+
 2019-10-15  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed, rolling out r251138.
diff --git a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
index d0089bf..444183b 100644
--- a/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
+++ b/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp
@@ -73,7 +73,9 @@
 
 void WebSWClientConnection::scheduleJobInServer(const ServiceWorkerJobData& jobData)
 {
-    send(Messages::WebSWServerConnection::ScheduleJobInServer { jobData });
+    runOrDelayTaskForImport([this, jobData] {
+        send(Messages::WebSWServerConnection::ScheduleJobInServer { jobData });
+    });
 }
 
 void WebSWClientConnection::finishFetchingScriptInServer(const ServiceWorkerFetchResult& result)