Title: [225758] trunk
Revision
225758
Author
cdu...@apple.com
Date
2017-12-11 14:49:10 -0800 (Mon, 11 Dec 2017)

Log Message

Layout Test http/tests/workers/service/postmessage-after-sw-process-crash.https.html is flaky
https://bugs.webkit.org/show_bug.cgi?id=180659

Reviewed by Youenn Fablet.

Source/WebKit:

Fix flaky crash due to capturing an IPC::DataReference in a lambda, which would point to invalid
memory when the lambda is called asynchronously.

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::postMessageToServiceWorkerFromClient):
(WebKit::WebSWServerConnection::postMessageToServiceWorkerFromServiceWorker):

LayoutTests:

Rewrite test so that it is no longer flaky.

* http/tests/workers/service/postmessage-after-sw-process-crash.https-expected.txt:
* http/tests/workers/service/resources/postmessage-after-sw-process-crash-worker.js: Added.
* http/tests/workers/service/resources/postmessage-after-sw-process-crash.js:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225757 => 225758)


--- trunk/LayoutTests/ChangeLog	2017-12-11 22:35:30 UTC (rev 225757)
+++ trunk/LayoutTests/ChangeLog	2017-12-11 22:49:10 UTC (rev 225758)
@@ -1,3 +1,16 @@
+2017-12-11  Chris Dumez  <cdu...@apple.com>
+
+        Layout Test http/tests/workers/service/postmessage-after-sw-process-crash.https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=180659
+
+        Reviewed by Youenn Fablet.
+
+        Rewrite test so that it is no longer flaky.
+
+        * http/tests/workers/service/postmessage-after-sw-process-crash.https-expected.txt:
+        * http/tests/workers/service/resources/postmessage-after-sw-process-crash-worker.js: Added.
+        * http/tests/workers/service/resources/postmessage-after-sw-process-crash.js:
+
 2017-12-11  David Quesada  <david_ques...@apple.com>
 
         Turn on ENABLE_APPLICATION_MANIFEST

Modified: trunk/LayoutTests/http/tests/workers/service/postmessage-after-sw-process-crash.https-expected.txt (225757 => 225758)


--- trunk/LayoutTests/http/tests/workers/service/postmessage-after-sw-process-crash.https-expected.txt	2017-12-11 22:35:30 UTC (rev 225757)
+++ trunk/LayoutTests/http/tests/workers/service/postmessage-after-sw-process-crash.https-expected.txt	2017-12-11 22:49:10 UTC (rev 225758)
@@ -1,8 +1,5 @@
-* Sending 'Message 1' to Service Worker
-PASS: Client received message from service worker, origin: https://127.0.0.1:8443
-PASS: Service worker received message 'Message 1' from origin 'https://127.0.0.1:8443'
+* Sending State to Service Worker
+* Asking Service Worker if it received the state
 * Simulating Service Worker process crash
-* Sending 'Message 2' to Service Worker
-PASS: Client received message from service worker, origin: https://127.0.0.1:8443
-PASS: Service worker received message 'Message 2' from origin 'https://127.0.0.1:8443'
+PASS: service worker lost the state and responded the postMessage after process termination
 

Added: trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash-worker.js (0 => 225758)


--- trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash-worker.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash-worker.js	2017-12-11 22:49:10 UTC (rev 225758)
@@ -0,0 +1,15 @@
+var client = null;
+let receivedState = false;
+
+self.addEventListener("message", (event) => {
+    if (event.data ="" "SetState") {
+        receivedState = true;
+        return;
+    }
+
+    if (event.data ="" "HasState") {
+        event.source.postMessage(receivedState);
+        return;
+    }
+});
+

Modified: trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash.js (225757 => 225758)


--- trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash.js	2017-12-11 22:35:30 UTC (rev 225757)
+++ trunk/LayoutTests/http/tests/workers/service/resources/postmessage-after-sw-process-crash.js	2017-12-11 22:49:10 UTC (rev 225758)
@@ -1,28 +1,46 @@
-var messageNumber = 1;
+let serviceWorkerHasReceivedState = false;
+let worker = null;
+let remainingAttempts = 1000; // We try for 10 seconds before timing out.
+
 navigator.serviceWorker.addEventListener("message", function(event) {
-    log("PASS: Client received message from service worker, origin: " + event.origin);
-    log(event.data);
-    if (messageNumber == 1) {
+    if (!serviceWorkerHasReceivedState) {
+        if (!event.data) {
+            log("FAIL: service worker did not receive the state");
+            finishSWTest();
+            return;
+        }
+        serviceWorkerHasReceivedState = true;
+
         log("* Simulating Service Worker process crash");
         testRunner.terminateServiceWorkerProcess();
-        setTimeout(function() {
-            log("* Sending 'Message 2' to Service Worker");
-            event.source.postMessage("Message 2");
-            messageNumber++;
-            handle = setTimeout(function() {
-                log("FAIL: Did not receive message from service worker process after the crash");
+
+        handle = setInterval(function() {
+            remainingAttempts--;
+            if (!remainingAttempts) {
+                log("FAIL: service worker did not respond after process termination");
+                clearInterval(handle);
                 finishSWTest();
-            }, 1000);
-        }, 0);
+                return;
+            }
+
+            worker.postMessage("HasState");
+        }, 10);
         return;
     }
-    if (messageNumber == 2) {
-        clearTimeout(handle);
-        finishSWTest();
-    }
+
+    // Worker still has the state, it was not terminated yet.
+    if (event.data ="" serviceWorkerHasReceivedState)
+        return;
+
+    log("PASS: service worker lost the state and responded the postMessage after process termination");
+    clearInterval(handle);
+    finishSWTest();
 });
 
-navigator.serviceWorker.register("resources/postmessage-echo-worker.js", { }).then(function(registration) {
-    log("* Sending 'Message 1' to Service Worker");
-    registration.installing.postMessage("Message 1");
+navigator.serviceWorker.register("resources/postmessage-after-sw-process-crash-worker.js", { }).then(function(registration) {
+    worker = registration.installing;
+    log("* Sending State to Service Worker");
+    worker.postMessage("SetState");
+    log("* Asking Service Worker if it received the state");
+    worker.postMessage("HasState");
 });

Modified: trunk/Source/WebKit/ChangeLog (225757 => 225758)


--- trunk/Source/WebKit/ChangeLog	2017-12-11 22:35:30 UTC (rev 225757)
+++ trunk/Source/WebKit/ChangeLog	2017-12-11 22:49:10 UTC (rev 225758)
@@ -1,3 +1,17 @@
+2017-12-11  Chris Dumez  <cdu...@apple.com>
+
+        Layout Test http/tests/workers/service/postmessage-after-sw-process-crash.https.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=180659
+
+        Reviewed by Youenn Fablet.
+
+        Fix flaky crash due to capturing an IPC::DataReference in a lambda, which would point to invalid
+        memory when the lambda is called asynchronously.
+
+        * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::postMessageToServiceWorkerFromClient):
+        (WebKit::WebSWServerConnection::postMessageToServiceWorkerFromServiceWorker):
+
 2017-12-11  Brent Fulgham  <bfulg...@apple.com>
 
         [iOS] Don't import 'UIKit-apps.sb' to the WebContent process sandbox

Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (225757 => 225758)


--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-12-11 22:35:30 UTC (rev 225757)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp	2017-12-11 22:49:10 UTC (rev 225758)
@@ -130,7 +130,7 @@
 void WebSWServerConnection::postMessageToServiceWorkerFromClient(ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference&& message, ServiceWorkerClientIdentifier sourceIdentifier, ServiceWorkerClientData&& sourceData)
 {
     // It's possible this specific worker cannot be re-run (e.g. its registration has been removed)
-    server().runServiceWorkerIfNecessary(destinationIdentifier, [destinationIdentifier, message = WTFMove(message), sourceIdentifier, sourceData = WTFMove(sourceData)](bool success, auto& contextConnection) mutable {
+    server().runServiceWorkerIfNecessary(destinationIdentifier, [destinationIdentifier, message = message.vector(), sourceIdentifier, sourceData = WTFMove(sourceData)](bool success, auto& contextConnection) mutable {
         if (success)
             sendToContextProcess(contextConnection, Messages::WebSWContextManagerConnection::PostMessageToServiceWorkerFromClient { destinationIdentifier, message, sourceIdentifier, WTFMove(sourceData) });
     });
@@ -143,7 +143,7 @@
         return;
 
     // It's possible this specific worker cannot be re-run (e.g. its registration has been removed)
-    server().runServiceWorkerIfNecessary(destinationIdentifier, [destinationIdentifier, message = WTFMove(message), sourceData = sourceWorker->data()](bool success, auto& contextConnection) mutable {
+    server().runServiceWorkerIfNecessary(destinationIdentifier, [destinationIdentifier, message = message.vector(), sourceData = sourceWorker->data()](bool success, auto& contextConnection) mutable {
         if (!success)
             return;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to