- Revision
- 290776
- Author
- [email protected]
- Date
- 2022-03-03 08:09:24 -0800 (Thu, 03 Mar 2022)
Log Message
REGRESSION(r290356-r290351?): [ iOS EWS ] 3 imported/w3c/web-platform-tests/service-workers/service-worker/* tests are constant text failures.
https://bugs.webkit.org/show_bug.cgi?id=237160
<rdar://problem/89440067>
Reviewed by Youenn Fablet.
LayoutTests/imported/w3c:
Rebaseline test that is now passing.
* web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https-expected.txt:
Source/WebCore:
In r290352, I made a change so that the service worker is more likely to launch in the WebContent
process that caused it to launch. This is beneficial for performance and memory usage.
The partitioned-service-worker*.html service worker tests are relying on an ID variable that is
randomly generated inside the service worker and they expect this ID to not change during the
duration of the test. This means that if the service worker exits / relaunches, those tests start
failing because the ID changes.
The issue is that we have logic in WebProcessProxy::didStartProvisionalLoadForMainFrame() that
terminates the service workers running inside the WebProcess if a new eTLD+1 page is loaded inside
the process. We do so to try and achieve better process isolation between different sites. The
issue is that those tests launch a service worker and then open a new cross-site popup. When the
cross-site popup loads inside the same process, we'd make the decision to terminate the service
workers in this process and relaunch them in a new clean one, causing the tests to fail.
While it is true per the specification that service workers can be terminated / relaunched at
almost any point, there are exceptions. In particular, we should keep a service worker running
if it still has pending extendable events. For this reason, the tests rely on FetchEvent.waitUntil()
to keep the service worker running. Sadly, we would not obey that in this case.
To address the issue, we no longer unconditionally close the service worker context connection
when a WebProcess loads a new eTLD+1. Instead, we tell the network process to close that connection
as soon as possible. When the network process receives this IPC, it terminates the context
connection ONLY if the service workers using the connection have no pending events. If we cannot
close the context connection right away, we set a flag on the context connection to indicate that
we should close it as soon as possible. Currently, this flag is only used to close the connection
right away (no 10 second delay) once the connection no longer has any clients. I think that, ideally,
we'd close the connection as soon as the service workers no longer have pending events. However,
this adds complexity and is error-prone so I didn't implement it in this patch and merely added a
FIXME comment. As it stands, my patch STILL relaunches service workers in origin-clean processes
in the common case. It only fails to do so in the case where there are pending service worker
events which is a case where we had the correctness bug anyway.
No new tests, unskipped existing tests.
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::forEachServiceWorker const):
(WebCore::SWServer::terminateContextConnectionWhenPossible):
(WebCore::SWServer::unregisterServiceWorkerClient):
* workers/service/server/SWServer.h:
* workers/service/server/SWServerToContextConnection.cpp:
(WebCore::SWServerToContextConnection::SWServerToContextConnection):
(WebCore::SWServerToContextConnection::server const):
(WebCore::SWServerToContextConnection::terminateWhenPossible):
* workers/service/server/SWServerToContextConnection.h:
(WebCore::SWServerToContextConnection::shouldTerminateWhenPossible const):
Source/WebKit:
In r290352, I made a change so that the service worker is more likely to launch in the WebContent
process that caused it to launch. This is beneficial for performance and memory usage.
The partitioned-service-worker*.html service worker tests are relying on an ID variable that is
randomly generated inside the service worker and they expect this ID to not change during the
duration of the test. This means that if the service worker exits / relaunches, those tests start
failing because the ID changes.
The issue is that we have logic in WebProcessProxy::didStartProvisionalLoadForMainFrame() that
terminates the service workers running inside the WebProcess if a new eTLD+1 page is loaded inside
the process. We do so to try and achieve better process isolation between different sites. The
issue is that those tests launch a service worker and then open a new cross-site popup. When the
cross-site popup loads inside the same process, we'd make the decision to terminate the service
workers in this process and relaunch them in a new clean one, causing the tests to fail.
While it is true per the specification that service workers can be terminated / relaunched at
almost any point, there are exceptions. In particular, we should keep a service worker running
if it still has pending extendable events. For this reason, the tests rely on FetchEvent.waitUntil()
to keep the service worker running. Sadly, we would not obey that in this case.
To address the issue, we no longer unconditionally close the service worker context connection
when a WebProcess loads a new eTLD+1. Instead, we tell the network process to close that connection
as soon as possible. When the network process receives this IPC, it terminates the context
connection ONLY if the service workers using the connection have no pending events. If we cannot
close the context connection right away, we set a flag on the context connection to indicate that
we should close it as soon as possible. Currently, this flag is only used to close the connection
right away (no 10 second delay) once the connection no longer has any clients. I think that, ideally,
we'd close the connection as soon as the service workers no longer have pending events. However,
this adds complexity and is error-prone so I didn't implement it in this patch and merely added a
FIXME comment. As it stands, my patch STILL relaunches service workers in origin-clean processes
in the common case. It only fails to do so in the case where there are pending service worker
events which is a case where we had the correctness bug anyway.
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::terminateRemoteWorkerContextConnectionWhenPossible):
* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
(WebKit::WebSWServerToContextConnection::WebSWServerToContextConnection):
(WebKit::WebSWServerToContextConnection::~WebSWServerToContextConnection):
(WebKit::WebSWServerToContextConnection::postMessageToServiceWorkerClient):
(WebKit::WebSWServerToContextConnection::close):
* NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
* NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp:
(WebKit::WebSharedWorkerServer::terminateContextConnectionWhenPossible):
* NetworkProcess/SharedWorker/WebSharedWorkerServer.h:
* NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp:
(WebKit::WebSharedWorkerServerToContextConnection::removeSharedWorkerObject):
* NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::terminateRemoteWorkerContextConnectionWhenPossible):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didStartProvisionalLoadForMainFrame):
LayoutTests:
Unskip tests that are no longer failing.
* platform/ios/TestExpectations:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (290775 => 290776)
--- trunk/LayoutTests/ChangeLog 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/LayoutTests/ChangeLog 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1,3 +1,15 @@
+2022-03-03 Chris Dumez <[email protected]>
+
+ REGRESSION(r290356-r290351?): [ iOS EWS ] 3 imported/w3c/web-platform-tests/service-workers/service-worker/* tests are constant text failures.
+ https://bugs.webkit.org/show_bug.cgi?id=237160
+ <rdar://problem/89440067>
+
+ Reviewed by Youenn Fablet.
+
+ Unskip tests that are no longer failing.
+
+ * platform/ios/TestExpectations:
+
2022-03-03 Martin Robinson <[email protected]>
Update WPT css-scroll-snap tests
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290775 => 290776)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1,3 +1,15 @@
+2022-03-03 Chris Dumez <[email protected]>
+
+ REGRESSION(r290356-r290351?): [ iOS EWS ] 3 imported/w3c/web-platform-tests/service-workers/service-worker/* tests are constant text failures.
+ https://bugs.webkit.org/show_bug.cgi?id=237160
+ <rdar://problem/89440067>
+
+ Reviewed by Youenn Fablet.
+
+ Rebaseline test that is now passing.
+
+ * web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https-expected.txt:
+
2022-03-03 Martin Robinson <[email protected]>
Update WPT css-scroll-snap tests
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https-expected.txt (290775 => 290776)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https-expected.txt 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https-expected.txt 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1,3 +1,3 @@
-FAIL The headers of FetchEvent shouldn't contain freshness headers. assert_false: if-none-match header must not be set in the FetchEvent's request. (url = "" expected false got true
+PASS The headers of FetchEvent shouldn't contain freshness headers.
Modified: trunk/LayoutTests/platform/ios/TestExpectations (290775 => 290776)
--- trunk/LayoutTests/platform/ios/TestExpectations 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2022-03-03 16:09:24 UTC (rev 290776)
@@ -2188,8 +2188,6 @@
webkit.org/b/152282 css3/filters/composited-during-transition-layertree.html [ Failure ]
-webkit.org/b/237160 imported/w3c/web-platform-tests/service-workers/service-worker/partitioned-service-worker.tentative.https.html [ Failure ]
-
webkit.org/b/152935 fast/scrolling/scroll-position-on-reload-rtl.html [ Failure ]
webkit.org/b/153371 imported/w3c/web-platform-tests/xhr/getresponseheader-chunked-trailer.htm [ Pass Failure ]
@@ -3504,7 +3502,3 @@
webkit.org/b/236794 editing/spelling/editing-word-with-marker-2.html [ Pass Crash ]
webkit.org/b/237159 imported/w3c/web-platform-tests/css/css-contain/content-visibility/content-visibility-049.html [ Pass Crash ]
-
-webkit.org/b/237161 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-no-freshness-headers.https.html [ Pass Failure ]
-
-webkit.org/b/237162 imported/w3c/web-platform-tests/service-workers/service-worker/partitioned-service-worker-getRegistrations.tentative.https.html [ Pass Failure ]
Modified: trunk/Source/WebCore/ChangeLog (290775 => 290776)
--- trunk/Source/WebCore/ChangeLog 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebCore/ChangeLog 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1,3 +1,58 @@
+2022-03-03 Chris Dumez <[email protected]>
+
+ REGRESSION(r290356-r290351?): [ iOS EWS ] 3 imported/w3c/web-platform-tests/service-workers/service-worker/* tests are constant text failures.
+ https://bugs.webkit.org/show_bug.cgi?id=237160
+ <rdar://problem/89440067>
+
+ Reviewed by Youenn Fablet.
+
+ In r290352, I made a change so that the service worker is more likely to launch in the WebContent
+ process that caused it to launch. This is beneficial for performance and memory usage.
+
+ The partitioned-service-worker*.html service worker tests are relying on an ID variable that is
+ randomly generated inside the service worker and they expect this ID to not change during the
+ duration of the test. This means that if the service worker exits / relaunches, those tests start
+ failing because the ID changes.
+
+ The issue is that we have logic in WebProcessProxy::didStartProvisionalLoadForMainFrame() that
+ terminates the service workers running inside the WebProcess if a new eTLD+1 page is loaded inside
+ the process. We do so to try and achieve better process isolation between different sites. The
+ issue is that those tests launch a service worker and then open a new cross-site popup. When the
+ cross-site popup loads inside the same process, we'd make the decision to terminate the service
+ workers in this process and relaunch them in a new clean one, causing the tests to fail.
+
+ While it is true per the specification that service workers can be terminated / relaunched at
+ almost any point, there are exceptions. In particular, we should keep a service worker running
+ if it still has pending extendable events. For this reason, the tests rely on FetchEvent.waitUntil()
+ to keep the service worker running. Sadly, we would not obey that in this case.
+
+ To address the issue, we no longer unconditionally close the service worker context connection
+ when a WebProcess loads a new eTLD+1. Instead, we tell the network process to close that connection
+ as soon as possible. When the network process receives this IPC, it terminates the context
+ connection ONLY if the service workers using the connection have no pending events. If we cannot
+ close the context connection right away, we set a flag on the context connection to indicate that
+ we should close it as soon as possible. Currently, this flag is only used to close the connection
+ right away (no 10 second delay) once the connection no longer has any clients. I think that, ideally,
+ we'd close the connection as soon as the service workers no longer have pending events. However,
+ this adds complexity and is error-prone so I didn't implement it in this patch and merely added a
+ FIXME comment. As it stands, my patch STILL relaunches service workers in origin-clean processes
+ in the common case. It only fails to do so in the case where there are pending service worker
+ events which is a case where we had the correctness bug anyway.
+
+ No new tests, unskipped existing tests.
+
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::forEachServiceWorker const):
+ (WebCore::SWServer::terminateContextConnectionWhenPossible):
+ (WebCore::SWServer::unregisterServiceWorkerClient):
+ * workers/service/server/SWServer.h:
+ * workers/service/server/SWServerToContextConnection.cpp:
+ (WebCore::SWServerToContextConnection::SWServerToContextConnection):
+ (WebCore::SWServerToContextConnection::server const):
+ (WebCore::SWServerToContextConnection::terminateWhenPossible):
+ * workers/service/server/SWServerToContextConnection.h:
+ (WebCore::SWServerToContextConnection::shouldTerminateWhenPossible const):
+
2022-03-03 Adrian Perez de Castro <[email protected]>
Non-unified build fixes, early March 2022 edition
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (290775 => 290776)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -736,6 +736,23 @@
}
}
+void SWServer::forEachServiceWorker(const Function<bool(const SWServerWorker&)>& apply) const
+{
+ for (auto& worker : m_runningOrTerminatingWorkers.values()) {
+ if (!apply(worker))
+ break;
+ }
+}
+
+void SWServer::terminateContextConnectionWhenPossible(const RegistrableDomain& registrableDomain, ProcessIdentifier processIdentifier)
+{
+ auto* contextConnection = contextConnectionForRegistrableDomain(registrableDomain);
+ if (!contextConnection || contextConnection->webProcessIdentifier() != processIdentifier)
+ return;
+
+ contextConnection->terminateWhenPossible();
+}
+
void SWServer::installContextData(const ServiceWorkerContextData& data)
{
ASSERT_WITH_MESSAGE(!data.loadedFromDisk, "Workers we just read from disk should only be launched as needed");
@@ -1036,7 +1053,9 @@
m_clientIdentifiersPerOrigin.remove(clientOrigin);
});
- iterator->value.terminateServiceWorkersTimer->startOneShot(m_isProcessTerminationDelayEnabled && !MemoryPressureHandler::singleton().isUnderMemoryPressure() && !didUnregister ? defaultTerminationDelay : 0_s);
+ auto* contextConnection = contextConnectionForRegistrableDomain(clientRegistrableDomain);
+ bool shouldContextConnectionBeTerminatedWhenPossible = contextConnection && contextConnection->shouldTerminateWhenPossible();
+ iterator->value.terminateServiceWorkersTimer->startOneShot(m_isProcessTerminationDelayEnabled && !MemoryPressureHandler::singleton().isUnderMemoryPressure() && !shouldContextConnectionBeTerminatedWhenPossible && !didUnregister ? defaultTerminationDelay : 0_s);
}
// If the app-bound value changed after this client was removed, we know it was the only app-bound
Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (290775 => 290776)
--- trunk/Source/WebCore/workers/service/server/SWServer.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -179,6 +179,7 @@
void workerContextTerminated(SWServerWorker&);
void matchAll(SWServerWorker&, const ServiceWorkerClientQueryOptions&, ServiceWorkerClientsMatchAllCallback&&);
std::optional<ExceptionData> claim(SWServerWorker&);
+ WEBCORE_EXPORT void terminateContextConnectionWhenPossible(const RegistrableDomain&, ProcessIdentifier);
WEBCORE_EXPORT static HashSet<SWServer*>& allServers();
@@ -228,6 +229,8 @@
ScriptExecutionContextIdentifier clientIdFromVisibleClientId(const String& visibleIdentifier) const { return m_visibleClientIdToInternalClientIdMap.get(visibleIdentifier); }
+ void forEachServiceWorker(const Function<bool(const SWServerWorker&)>&) const;
+
private:
void validateRegistrationDomain(WebCore::RegistrableDomain, ServiceWorkerJobType, CompletionHandler<void(bool)>&&);
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp (290775 => 290776)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -40,8 +40,9 @@
return SWServerToContextConnectionIdentifier::generate();
}
-SWServerToContextConnection::SWServerToContextConnection(RegistrableDomain&& registrableDomain, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier)
- : m_identifier(generateServerToContextConnectionIdentifier())
+SWServerToContextConnection::SWServerToContextConnection(SWServer& server, RegistrableDomain&& registrableDomain, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier)
+ : m_server(server)
+ , m_identifier(generateServerToContextConnectionIdentifier())
, m_registrableDomain(WTFMove(registrableDomain))
, m_serviceWorkerPageIdentifier(serviceWorkerPageIdentifier)
{
@@ -51,6 +52,11 @@
{
}
+SWServer* SWServerToContextConnection::server() const
+{
+ return m_server.get();
+}
+
void SWServerToContextConnection::scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>& jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& message)
{
if (auto* worker = SWServerWorker::existingWorkerForIdentifier(serviceWorkerIdentifier))
@@ -131,6 +137,25 @@
worker->didFailHeartBeatCheck();
}
+void SWServerToContextConnection::terminateWhenPossible()
+{
+ m_shouldTerminateWhenPossible = true;
+
+ bool hasServiceWorkerWithPendingEvents = false;
+ server()->forEachServiceWorker([&](auto& worker) {
+ if (worker.isRunning() && worker.registrableDomain() == m_registrableDomain && worker.hasPendingEvents()) {
+ hasServiceWorkerWithPendingEvents = true;
+ return false;
+ }
+ return true;
+ });
+
+ // FIXME: If there is a service worker with pending events and we don't close the connection right away, we'd ideally keep
+ // track of this and close the connection once it becomes idle.
+ if (!hasServiceWorkerWithPendingEvents)
+ close();
+}
+
} // namespace WebCore
#endif // ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h (290775 => 290776)
--- trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebCore/workers/service/server/SWServerToContextConnection.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -49,8 +49,13 @@
public:
WEBCORE_EXPORT virtual ~SWServerToContextConnection();
+ WEBCORE_EXPORT SWServer* server() const;
SWServerToContextConnectionIdentifier identifier() const { return m_identifier; }
+ // This flag gets set when the service worker process is no longer clean (because it has loaded several eTLD+1s).
+ bool shouldTerminateWhenPossible() const { return m_shouldTerminateWhenPossible; }
+ void terminateWhenPossible();
+
// Messages to the SW host process
virtual void installServiceWorkerContext(const ServiceWorkerContextData&, const ServiceWorkerData&, const String& userAgent, WorkerThreadMode) = 0;
virtual void updateAppInitiatedValue(ServiceWorkerIdentifier, LastNavigationWasAppInitiated) = 0;
@@ -60,6 +65,7 @@
virtual void didSaveScriptsToDisk(ServiceWorkerIdentifier, const ScriptBuffer&, const HashMap<URL, ScriptBuffer>& importedScripts) = 0;
virtual void matchAllCompleted(uint64_t requestIdentifier, const Vector<ServiceWorkerClientData>&) = 0;
virtual void firePushEvent(ServiceWorkerIdentifier, const std::optional<Vector<uint8_t>>&, CompletionHandler<void(bool)>&& callback) = 0;
+ virtual ProcessIdentifier webProcessIdentifier() const = 0;
// Messages back from the SW host process
WEBCORE_EXPORT void scriptContextFailedToStart(const std::optional<ServiceWorkerJobDataIdentifier>&, ServiceWorkerIdentifier, const String& message);
@@ -82,12 +88,16 @@
virtual void terminateDueToUnresponsiveness() = 0;
protected:
- WEBCORE_EXPORT SWServerToContextConnection(RegistrableDomain&&, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier);
+ WEBCORE_EXPORT SWServerToContextConnection(SWServer&, RegistrableDomain&&, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier);
+ virtual void close() = 0;
+
private:
+ WeakPtr<WebCore::SWServer> m_server;
SWServerToContextConnectionIdentifier m_identifier;
RegistrableDomain m_registrableDomain;
std::optional<ScriptExecutionContextIdentifier> m_serviceWorkerPageIdentifier;
+ bool m_shouldTerminateWhenPossible { false };
};
} // namespace WebCore
Modified: trunk/Source/WebKit/ChangeLog (290775 => 290776)
--- trunk/Source/WebKit/ChangeLog 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/ChangeLog 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1,3 +1,66 @@
+2022-03-03 Chris Dumez <[email protected]>
+
+ REGRESSION(r290356-r290351?): [ iOS EWS ] 3 imported/w3c/web-platform-tests/service-workers/service-worker/* tests are constant text failures.
+ https://bugs.webkit.org/show_bug.cgi?id=237160
+ <rdar://problem/89440067>
+
+ Reviewed by Youenn Fablet.
+
+ In r290352, I made a change so that the service worker is more likely to launch in the WebContent
+ process that caused it to launch. This is beneficial for performance and memory usage.
+
+ The partitioned-service-worker*.html service worker tests are relying on an ID variable that is
+ randomly generated inside the service worker and they expect this ID to not change during the
+ duration of the test. This means that if the service worker exits / relaunches, those tests start
+ failing because the ID changes.
+
+ The issue is that we have logic in WebProcessProxy::didStartProvisionalLoadForMainFrame() that
+ terminates the service workers running inside the WebProcess if a new eTLD+1 page is loaded inside
+ the process. We do so to try and achieve better process isolation between different sites. The
+ issue is that those tests launch a service worker and then open a new cross-site popup. When the
+ cross-site popup loads inside the same process, we'd make the decision to terminate the service
+ workers in this process and relaunch them in a new clean one, causing the tests to fail.
+
+ While it is true per the specification that service workers can be terminated / relaunched at
+ almost any point, there are exceptions. In particular, we should keep a service worker running
+ if it still has pending extendable events. For this reason, the tests rely on FetchEvent.waitUntil()
+ to keep the service worker running. Sadly, we would not obey that in this case.
+
+ To address the issue, we no longer unconditionally close the service worker context connection
+ when a WebProcess loads a new eTLD+1. Instead, we tell the network process to close that connection
+ as soon as possible. When the network process receives this IPC, it terminates the context
+ connection ONLY if the service workers using the connection have no pending events. If we cannot
+ close the context connection right away, we set a flag on the context connection to indicate that
+ we should close it as soon as possible. Currently, this flag is only used to close the connection
+ right away (no 10 second delay) once the connection no longer has any clients. I think that, ideally,
+ we'd close the connection as soon as the service workers no longer have pending events. However,
+ this adds complexity and is error-prone so I didn't implement it in this patch and merely added a
+ FIXME comment. As it stands, my patch STILL relaunches service workers in origin-clean processes
+ in the common case. It only fails to do so in the case where there are pending service worker
+ events which is a case where we had the correctness bug anyway.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::NetworkProcess::terminateRemoteWorkerContextConnectionWhenPossible):
+ * NetworkProcess/NetworkProcess.h:
+ * NetworkProcess/NetworkProcess.messages.in:
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp:
+ (WebKit::WebSWServerToContextConnection::WebSWServerToContextConnection):
+ (WebKit::WebSWServerToContextConnection::~WebSWServerToContextConnection):
+ (WebKit::WebSWServerToContextConnection::postMessageToServiceWorkerClient):
+ (WebKit::WebSWServerToContextConnection::close):
+ * NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h:
+ * NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp:
+ (WebKit::WebSharedWorkerServer::terminateContextConnectionWhenPossible):
+ * NetworkProcess/SharedWorker/WebSharedWorkerServer.h:
+ * NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp:
+ (WebKit::WebSharedWorkerServerToContextConnection::removeSharedWorkerObject):
+ * NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h:
+ * UIProcess/Network/NetworkProcessProxy.cpp:
+ (WebKit::NetworkProcessProxy::terminateRemoteWorkerContextConnectionWhenPossible):
+ * UIProcess/Network/NetworkProcessProxy.h:
+ * UIProcess/WebProcessProxy.cpp:
+ (WebKit::WebProcessProxy::didStartProvisionalLoadForMainFrame):
+
2022-03-03 Adrian Perez de Castro <[email protected]>
Non-unified build fixes, early March 2022 edition
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -51,6 +51,7 @@
#include "NetworkStorageManager.h"
#include "PreconnectTask.h"
#include "PrivateClickMeasurementStore.h"
+#include "RemoteWorkerType.h"
#include "ShouldGrandfatherStatistics.h"
#include "StorageAccessStatus.h"
#include "StorageManagerSet.h"
@@ -60,6 +61,7 @@
#include "WebProcessPoolMessages.h"
#include "WebPushMessage.h"
#include "WebResourceLoadStatisticsStore.h"
+#include "WebSharedWorkerServer.h"
#include "WebsiteDataFetchOption.h"
#include "WebsiteDataStore.h"
#include "WebsiteDataStoreParameters.h"
@@ -2077,6 +2079,24 @@
prepareToSuspend(true, WTFMove(completionHandler));
}
+void NetworkProcess::terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType workerType, PAL::SessionID sessionID, const WebCore::RegistrableDomain& registrableDomain, WebCore::ProcessIdentifier processIdentifier)
+{
+ auto* session = networkSession(sessionID);
+ if (!session)
+ return;
+
+ switch (workerType) {
+ case RemoteWorkerType::ServiceWorker:
+ if (auto* swServer = session->swServer())
+ swServer->terminateContextConnectionWhenPossible(registrableDomain, processIdentifier);
+ break;
+ case RemoteWorkerType::SharedWorker:
+ if (auto* sharedWorkerServer = session->sharedWorkerServer())
+ sharedWorkerServer->terminateContextConnectionWhenPossible(registrableDomain, processIdentifier);
+ break;
+ }
+}
+
void NetworkProcess::prepareToSuspend(bool isSuspensionImminent, CompletionHandler<void()>&& completionHandler)
{
RELEASE_LOG(ProcessSuspension, "%p - NetworkProcess::prepareToSuspend(), isSuspensionImminent=%d", this, isSuspensionImminent);
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.h (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -107,6 +107,7 @@
class ProcessAssertion;
class WebPageNetworkParameters;
enum class CallDownloadDidStart : bool;
+enum class RemoteWorkerType : bool;
enum class ShouldGrandfatherStatistics : bool;
enum class StorageAccessStatus : uint8_t;
enum class WebsiteDataFetchOption : uint8_t;
@@ -461,6 +462,7 @@
static void setSharedHTTPCookieStorage(const Vector<uint8_t>& identifier);
#endif
+ void terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType, PAL::SessionID, const WebCore::RegistrableDomain&, WebCore::ProcessIdentifier);
void platformFlushCookies(PAL::SessionID, CompletionHandler<void()>&&);
void registerURLSchemeAsSecure(const String&) const;
Modified: trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/NetworkProcess.messages.in 2022-03-03 16:09:24 UTC (rev 290776)
@@ -207,6 +207,8 @@
NotifyPreferencesChanged(String domain, String key, std::optional<String> encodedValue)
#endif
+ TerminateRemoteWorkerContextConnectionWhenPossible(enum:bool WebKit::RemoteWorkerType workerType, PAL::SessionID sessionID, WebCore::RegistrableDomain registrableDomain, WebCore::ProcessIdentifier processIdentifier);
+
#if ENABLE(SERVICE_WORKER)
GetPendingPushMessages(PAL::SessionID sessionID) -> (Vector<WebKit::WebPushMessage> messages) Async
ProcessPushMessage(PAL::SessionID sessionID, struct WebKit::WebPushMessage pushMessage) -> (bool didSucceed) Async
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -46,9 +46,8 @@
using namespace WebCore;
WebSWServerToContextConnection::WebSWServerToContextConnection(NetworkConnectionToWebProcess& connection, WebPageProxyIdentifier webPageProxyID, RegistrableDomain&& registrableDomain, std::optional<ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier, SWServer& server)
- : SWServerToContextConnection(WTFMove(registrableDomain), serviceWorkerPageIdentifier)
+ : SWServerToContextConnection(server, WTFMove(registrableDomain), serviceWorkerPageIdentifier)
, m_connection(connection)
- , m_server(server)
, m_webPageProxyID(webPageProxyID)
{
server.addContextConnection(*this);
@@ -64,8 +63,8 @@
for (auto& download : downloads.values())
download->contextClosed();
- if (m_server && m_server->contextConnectionForRegistrableDomain(registrableDomain()) == this)
- m_server->removeContextConnection(*this);
+ if (auto* server = this->server(); server && server->contextConnectionForRegistrableDomain(registrableDomain()) == this)
+ server->removeContextConnection(*this);
}
IPC::Connection& WebSWServerToContextConnection::ipcConnection() const
@@ -85,13 +84,16 @@
void WebSWServerToContextConnection::postMessageToServiceWorkerClient(const ScriptExecutionContextIdentifier& destinationIdentifier, const MessageWithMessagePorts& message, ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin)
{
- if (!m_server)
- return;
-
- if (auto* connection = m_server->connection(destinationIdentifier.processIdentifier()))
+ auto* server = this->server();
+ if (auto* connection = server ? server->connection(destinationIdentifier.processIdentifier()) : nullptr)
connection->postMessageToServiceWorkerClient(destinationIdentifier, message, sourceIdentifier, sourceOrigin);
}
+void WebSWServerToContextConnection::close()
+{
+ send(Messages::WebSWContextManagerConnection::Close { });
+}
+
void WebSWServerToContextConnection::installServiceWorkerContext(const ServiceWorkerContextData& contextData, const ServiceWorkerData& workerData, const String& userAgent, WorkerThreadMode workerThreadMode)
{
send(Messages::WebSWContextManagerConnection::InstallServiceWorker { contextData, workerData, userAgent, workerThreadMode });
Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/WebSWServerToContextConnection.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -55,7 +55,7 @@
class NetworkConnectionToWebProcess;
class WebSWServerConnection;
-class WebSWServerToContextConnection: public WebCore::SWServerToContextConnection, public IPC::MessageSender, public IPC::MessageReceiver {
+class WebSWServerToContextConnection final: public WebCore::SWServerToContextConnection, public IPC::MessageSender, public IPC::MessageReceiver {
public:
WebSWServerToContextConnection(NetworkConnectionToWebProcess&, WebPageProxyIdentifier, WebCore::RegistrableDomain&&, std::optional<WebCore::ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier, WebCore::SWServer&);
~WebSWServerToContextConnection();
@@ -78,7 +78,7 @@
void registerDownload(ServiceWorkerDownloadTask&);
void unregisterDownload(ServiceWorkerDownloadTask&);
- WebCore::ProcessIdentifier webProcessIdentifier() const;
+ WebCore::ProcessIdentifier webProcessIdentifier() const final;
NetworkProcess& networkProcess() { return m_connection.networkProcess(); }
private:
@@ -97,6 +97,7 @@
void didSaveScriptsToDisk(WebCore::ServiceWorkerIdentifier, const WebCore::ScriptBuffer&, const HashMap<URL, WebCore::ScriptBuffer>& importedScripts) final;
void matchAllCompleted(uint64_t requestIdentifier, const Vector<WebCore::ServiceWorkerClientData>&) final;
void firePushEvent(WebCore::ServiceWorkerIdentifier, const std::optional<Vector<uint8_t>>&, CompletionHandler<void(bool)>&&) final;
+ void close() final;
void connectionIsNoLongerNeeded() final;
void terminateDueToUnresponsiveness() final;
@@ -104,7 +105,6 @@
void connectionClosed();
NetworkConnectionToWebProcess& m_connection;
- WeakPtr<WebCore::SWServer> m_server;
HashMap<WebCore::FetchIdentifier, WeakPtr<ServiceWorkerFetchTask>> m_ongoingFetches;
HashMap<WebCore::FetchIdentifier, WeakPtr<ServiceWorkerDownloadTask>> m_ongoingDownloads;
bool m_isThrottleable { true };
Modified: trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -259,4 +259,14 @@
});
}
+void WebSharedWorkerServer::terminateContextConnectionWhenPossible(const WebCore::RegistrableDomain& registrableDomain, WebCore::ProcessIdentifier processIdentifier)
+{
+ auto* contextConnection = contextConnectionForRegistrableDomain(registrableDomain);
+ RELEASE_LOG(SharedWorker, "WebSharedWorkerServer::terminateContextConnectionWhenPossible: processIdentifier=%" PRIu64 ", contextConnection=%p", processIdentifier.toUInt64(), contextConnection);
+ if (!contextConnection || contextConnection->webProcessIdentifier() != processIdentifier)
+ return;
+
+ contextConnection->terminateWhenPossible();
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.h (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServer.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -65,6 +65,7 @@
void sharedWorkerObjectIsGoingAway(const WebCore::SharedWorkerKey&, WebCore::SharedWorkerObjectIdentifier);
void postExceptionToWorkerObject(WebCore::SharedWorkerIdentifier, const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL);
+ void terminateContextConnectionWhenPossible(const WebCore::RegistrableDomain&, WebCore::ProcessIdentifier);
void addContextConnection(WebSharedWorkerServerToContextConnection&);
void removeContextConnection(WebSharedWorkerServerToContextConnection&);
void addConnection(std::unique_ptr<WebSharedWorkerServerConnection>&&);
Modified: trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -148,7 +148,7 @@
if (m_sharedWorkerObjects.isEmpty()) {
CONTEXT_CONNECTION_RELEASE_LOG("removeSharedWorkerObject: connection is now idle, starting a timer to terminate it");
ASSERT(!m_idleTerminationTimer.isActive());
- m_idleTerminationTimer.startOneShot(MemoryPressureHandler::singleton().isUnderMemoryPressure() ? 0_s : idleTerminationDelay);
+ m_idleTerminationTimer.startOneShot(MemoryPressureHandler::singleton().isUnderMemoryPressure() || m_shouldTerminateWhenPossible ? 0_s : idleTerminationDelay);
}
}
Modified: trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h (290775 => 290776)
--- trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -58,6 +58,8 @@
const WebCore::RegistrableDomain& registrableDomain() const { return m_registrableDomain; }
IPC::Connection& ipcConnection() const;
+ void terminateWhenPossible() { m_shouldTerminateWhenPossible = true; }
+
void launchSharedWorker(WebSharedWorker&);
void postConnectEvent(const WebSharedWorker&, const WebCore::TransferredMessagePort&);
void terminateSharedWorker(const WebSharedWorker&);
@@ -85,6 +87,7 @@
WebCore::RegistrableDomain m_registrableDomain;
HashMap<WebCore::ProcessIdentifier, HashSet<WebCore::SharedWorkerObjectIdentifier>> m_sharedWorkerObjects;
WebCore::Timer m_idleTerminationTimer;
+ bool m_shouldTerminateWhenPossible { false };
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (290775 => 290776)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1782,6 +1782,11 @@
sendWithAsyncReply(Messages::NetworkProcess::GetOriginsWithPushAndNotificationPermissions { sessionID }, WTFMove(callback));
}
+void NetworkProcessProxy::terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType workerType, PAL::SessionID sessionID, const WebCore::RegistrableDomain& registrableDomain, WebCore::ProcessIdentifier processIdentifier)
+{
+ send(Messages::NetworkProcess::TerminateRemoteWorkerContextConnectionWhenPossible(workerType, sessionID, registrableDomain, processIdentifier), 0);
+}
+
} // namespace WebKit
#undef MESSAGE_CHECK
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (290775 => 290776)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h 2022-03-03 16:09:24 UTC (rev 290776)
@@ -299,6 +299,8 @@
void dataTaskDidCompleteWithError(DataTaskIdentifier, WebCore::ResourceError&&);
void cancelDataTask(DataTaskIdentifier, PAL::SessionID);
+ void terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType, PAL::SessionID, const WebCore::RegistrableDomain&, WebCore::ProcessIdentifier);
+
private:
explicit NetworkProcessProxy();
Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (290775 => 290776)
--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2022-03-03 15:22:11 UTC (rev 290775)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2022-03-03 16:09:24 UTC (rev 290776)
@@ -1689,9 +1689,10 @@
auto registrableDomain = WebCore::RegistrableDomain { url };
if (m_registrableDomain && *m_registrableDomain != registrableDomain) {
-#if ENABLE(SERVICE_WORKER)
- disableRemoteWorkers(RemoteWorkerType::ServiceWorker);
-#endif
+ if (isRunningServiceWorkers())
+ websiteDataStore().networkProcess().terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType::ServiceWorker, websiteDataStore().sessionID(), *m_registrableDomain, coreProcessIdentifier());
+ if (isRunningSharedWorkers())
+ websiteDataStore().networkProcess().terminateRemoteWorkerContextConnectionWhenPossible(RemoteWorkerType::SharedWorker, websiteDataStore().sessionID(), *m_registrableDomain, coreProcessIdentifier());
// Null out registrable domain since this process has now been used for several domains.
m_registrableDomain = WebCore::RegistrableDomain { };