Title: [243812] trunk/Source/WebCore
Revision
243812
Author
[email protected]
Date
2019-04-03 10:45:17 -0700 (Wed, 03 Apr 2019)

Log Message

Clear WorkerCacheStorageConnection callbacks on WorkerGlobalScope termination
https://bugs.webkit.org/show_bug.cgi?id=196521

Reviewed by Alex Christensen.

When the worker global scope is preparing for termination,
all ActiveDOMObjects are stopped.
At that time, the completion handlers related to
WorkerCacheStorageConnection should be cleared to be able to free
memory, and as they are now no-op anyway.

We clear the completion handlers once the active DOM objects are stopped
to limit the processing triggered by clearing them.

Introducing a new Stopped error code to handle this case.
Add an assertion so that this error does not surface to JS.

Covered by existing tests.

* Modules/cache/CacheStorageConnection.cpp:
(WebCore::CacheStorageConnection::clearPendingRequests):
* Modules/cache/CacheStorageConnection.h:
* Modules/cache/DOMCacheEngine.cpp:
(WebCore::DOMCacheEngine::errorToException):
* Modules/cache/DOMCacheEngine.h:
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::prepareForTermination):
(WebCore::WorkerGlobalScope::stopIndexedDatabase):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (243811 => 243812)


--- trunk/Source/WebCore/ChangeLog	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/ChangeLog	2019-04-03 17:45:17 UTC (rev 243812)
@@ -1,5 +1,36 @@
 2019-04-03  Youenn Fablet  <[email protected]>
 
+        Clear WorkerCacheStorageConnection callbacks on WorkerGlobalScope termination
+        https://bugs.webkit.org/show_bug.cgi?id=196521
+
+        Reviewed by Alex Christensen.
+
+        When the worker global scope is preparing for termination,
+        all ActiveDOMObjects are stopped.
+        At that time, the completion handlers related to
+        WorkerCacheStorageConnection should be cleared to be able to free
+        memory, and as they are now no-op anyway.
+
+        We clear the completion handlers once the active DOM objects are stopped
+        to limit the processing triggered by clearing them.
+
+        Introducing a new Stopped error code to handle this case.
+        Add an assertion so that this error does not surface to JS.
+
+        Covered by existing tests.
+
+        * Modules/cache/CacheStorageConnection.cpp:
+        (WebCore::CacheStorageConnection::clearPendingRequests):
+        * Modules/cache/CacheStorageConnection.h:
+        * Modules/cache/DOMCacheEngine.cpp:
+        (WebCore::DOMCacheEngine::errorToException):
+        * Modules/cache/DOMCacheEngine.h:
+        * workers/WorkerGlobalScope.cpp:
+        (WebCore::WorkerGlobalScope::prepareForTermination):
+        (WebCore::WorkerGlobalScope::stopIndexedDatabase):
+
+2019-04-03  Youenn Fablet  <[email protected]>
+
         Adopt new VCP SPI
         https://bugs.webkit.org/show_bug.cgi?id=193357
         <rdar://problem/43656651>

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp (243811 => 243812)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.cpp	2019-04-03 17:45:17 UTC (rev 243812)
@@ -33,6 +33,25 @@
 namespace WebCore {
 using namespace WebCore::DOMCacheEngine;
 
+void CacheStorageConnection::clearPendingRequests()
+{
+    auto openAndRemoveCachePendingRequests = WTFMove(m_openAndRemoveCachePendingRequests);
+    for (auto& callback : openAndRemoveCachePendingRequests.values())
+        callback(makeUnexpected(DOMCacheEngine::Error::Stopped));
+
+    auto retrieveCachesPendingRequests = WTFMove(m_retrieveCachesPendingRequests);
+    for (auto& callback : retrieveCachesPendingRequests.values())
+        callback(makeUnexpected(DOMCacheEngine::Error::Stopped));
+
+    auto retrieveRecordsPendingRequests = WTFMove(m_retrieveRecordsPendingRequests);
+    for (auto& callback : retrieveRecordsPendingRequests.values())
+        callback(makeUnexpected(DOMCacheEngine::Error::Stopped));
+
+    auto batchDeleteAndPutPendingRequests = WTFMove(m_batchDeleteAndPutPendingRequests);
+    for (auto& callback : batchDeleteAndPutPendingRequests.values())
+        callback(makeUnexpected(DOMCacheEngine::Error::Stopped));
+}
+
 void CacheStorageConnection::open(const ClientOrigin& origin, const String& cacheName, CacheIdentifierCallback&& callback)
 {
     uint64_t requestIdentifier = ++m_lastRequestIdentifier;

Modified: trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h (243811 => 243812)


--- trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/Modules/cache/CacheStorageConnection.h	2019-04-03 17:45:17 UTC (rev 243812)
@@ -57,6 +57,8 @@
     virtual void engineRepresentation(WTF::Function<void(const String&)>&& callback) { callback(String { }); }
     virtual void updateQuotaBasedOnSpaceUsage(const ClientOrigin&) { }
 
+    void clearPendingRequests();
+
 protected:
     CacheStorageConnection() =  default;
 

Modified: trunk/Source/WebCore/Modules/cache/DOMCacheEngine.cpp (243811 => 243812)


--- trunk/Source/WebCore/Modules/cache/DOMCacheEngine.cpp	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/Modules/cache/DOMCacheEngine.cpp	2019-04-03 17:45:17 UTC (rev 243812)
@@ -46,8 +46,11 @@
         return Exception { TypeError, "Failed writing data to the file system"_s };
     case Error::QuotaExceeded:
         return Exception { QuotaExceededError, "Quota exceeded"_s };
+    case Error::Internal:
+        return Exception { TypeError, "Internal error"_s };
     default:
-        return Exception { TypeError, "Internal error"_s };
+        ASSERT_NOT_REACHED();
+        return Exception { TypeError, "Connection stopped"_s };
     }
 }
 

Modified: trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h (243811 => 243812)


--- trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/Modules/cache/DOMCacheEngine.h	2019-04-03 17:45:17 UTC (rev 243812)
@@ -44,7 +44,8 @@
     ReadDisk,
     WriteDisk,
     QuotaExceeded,
-    Internal
+    Internal,
+    Stopped
 };
 
 Exception convertToExceptionAndLog(ScriptExecutionContext*, Error);

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (243811 => 243812)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2019-04-03 17:37:55 UTC (rev 243811)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp	2019-04-03 17:45:17 UTC (rev 243812)
@@ -113,6 +113,9 @@
 
     stopActiveDOMObjects();
 
+    if (m_cacheStorageConnection)
+        m_cacheStorageConnection->clearPendingRequests();
+
     m_inspectorController->workerTerminating();
 
     // Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to