Modern IDB: When IDBDatabase objects are garbage collected, they don't close their...
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jul 2016 21:49:41 +0000 (21:49 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 Jul 2016 21:49:41 +0000 (21:49 +0000)
<rdar://problem/25910345> and https://bugs.webkit.org/show_bug.cgi?id=159523

Reviewed by Alex Christensen.

Source/WebCore:

Tests: storage/indexeddb/modern/gc-closes-database-private.html
       storage/indexeddb/modern/gc-closes-database.html

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::IDBDatabase): New logging.
(WebCore::IDBDatabase::~IDBDatabase): Close server connection.
(WebCore::IDBDatabase::fireVersionChangeEvent): New logging.
(WebCore::IDBDatabase::dispatchEvent): New logging.

* Modules/indexeddb/client/IDBConnectionToServer.cpp:
(WebCore::IDBClient::IDBConnectionToServer::openDatabase): New logging.

LayoutTests:

* storage/indexeddb/modern/gc-closes-database-expected.txt: Added.
* storage/indexeddb/modern/gc-closes-database-private-expected.txt: Added.
* storage/indexeddb/modern/gc-closes-database-private.html: Added.
* storage/indexeddb/modern/gc-closes-database.html: Added.
* storage/indexeddb/modern/resources/gc-closes-database.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/modern/gc-closes-database-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/gc-closes-database-private-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/gc-closes-database-private.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/gc-closes-database.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/modern/resources/gc-closes-database.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/client/IDBConnectionToServer.cpp

index ee87f74..db2f610 100644 (file)
@@ -1,3 +1,16 @@
+2016-07-07  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: When IDBDatabase objects are garbage collected, they don't close their server connection.
+        <rdar://problem/25910345> and https://bugs.webkit.org/show_bug.cgi?id=159523
+
+        Reviewed by Alex Christensen.
+
+        * storage/indexeddb/modern/gc-closes-database-expected.txt: Added.
+        * storage/indexeddb/modern/gc-closes-database-private-expected.txt: Added.
+        * storage/indexeddb/modern/gc-closes-database-private.html: Added.
+        * storage/indexeddb/modern/gc-closes-database.html: Added.
+        * storage/indexeddb/modern/resources/gc-closes-database.js: Added.
+
 2016-07-07  Frederic Wang  <fwang@igalia.com>
 
         Refactor layout functions to avoid using flexbox in MathML
diff --git a/LayoutTests/storage/indexeddb/modern/gc-closes-database-expected.txt b/LayoutTests/storage/indexeddb/modern/gc-closes-database-expected.txt
new file mode 100644 (file)
index 0000000..eeafe0b
--- /dev/null
@@ -0,0 +1,14 @@
+This tests that when IDBDatabase objects are destroyed in garbage collection that their database handles are closed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Database deleted
+Creating the default database
+Database upgraded to version 1
+Database created
+Huge upgrade open success
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/modern/gc-closes-database-private-expected.txt b/LayoutTests/storage/indexeddb/modern/gc-closes-database-private-expected.txt
new file mode 100644 (file)
index 0000000..eeafe0b
--- /dev/null
@@ -0,0 +1,14 @@
+This tests that when IDBDatabase objects are destroyed in garbage collection that their database handles are closed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Database deleted
+Creating the default database
+Database upgraded to version 1
+Database created
+Huge upgrade open success
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/modern/gc-closes-database-private.html b/LayoutTests/storage/indexeddb/modern/gc-closes-database-private.html
new file mode 100644 (file)
index 0000000..e28bb72
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/gc-closes-database.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/modern/gc-closes-database.html b/LayoutTests/storage/indexeddb/modern/gc-closes-database.html
new file mode 100644 (file)
index 0000000..e28bb72
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../resources/shared.js"></script>
+</head>
+<body>
+<script src="resources/gc-closes-database.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/modern/resources/gc-closes-database.js b/LayoutTests/storage/indexeddb/modern/resources/gc-closes-database.js
new file mode 100644 (file)
index 0000000..5fcc0f0
--- /dev/null
@@ -0,0 +1,56 @@
+description("This tests that when IDBDatabase objects are destroyed in garbage collection that their database handles are closed.");
+
+function done()
+{
+    finishJSTest();
+}
+
+function log(msg)
+{
+    debug(msg);
+}
+
+var databaseName;
+
+
+deleteRequest = indexedDB.deleteDatabase("gc-closes-database");
+deleteRequest.onsuccess = function() {
+    log("Database deleted");
+    continueTest();
+}
+
+deleteRequest.onerror = function() {
+    log("Error deleting database");
+    done();
+}
+
+function continueTest()
+{
+    log("Creating the default database");
+    var openRequest = indexedDB.open("gc-closes-database");
+
+    openRequest.onupgradeneeded = function(e) {
+        log("Database upgraded to version 1");
+    }
+    
+    openRequest.onsuccess = function(e) {
+        log("Database created");
+        setTimeout(window.gc, 0);
+    }
+
+    openRequest.onerror = function() {
+        log("Error opening database");
+        done();
+    }
+
+    hugeUpgradeOpen = indexedDB.open("gc-closes-database", 928375298375);
+    hugeUpgradeOpen.onsuccess = function(e) {
+        log("Huge upgrade open success");
+        done();
+    }
+    hugeUpgradeOpen.onerror = function() {
+        log("Unexpected error");
+        done();
+    }
+
+}
index 4762627..0f124bc 100644 (file)
@@ -1,3 +1,22 @@
+2016-07-07  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: When IDBDatabase objects are garbage collected, they don't close their server connection.
+        <rdar://problem/25910345> and https://bugs.webkit.org/show_bug.cgi?id=159523
+
+        Reviewed by Alex Christensen.
+
+        Tests: storage/indexeddb/modern/gc-closes-database-private.html
+               storage/indexeddb/modern/gc-closes-database.html
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::IDBDatabase): New logging.
+        (WebCore::IDBDatabase::~IDBDatabase): Close server connection.
+        (WebCore::IDBDatabase::fireVersionChangeEvent): New logging.
+        (WebCore::IDBDatabase::dispatchEvent): New logging.
+
+        * Modules/indexeddb/client/IDBConnectionToServer.cpp:
+        (WebCore::IDBClient::IDBConnectionToServer::openDatabase): New logging.
+
 2016-07-07  Frederic Wang  <fwang@igalia.com>
 
         Refactor layout functions to avoid using flexbox in MathML
index 651e409..cdab15b 100644 (file)
@@ -55,7 +55,7 @@ IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnecti
     , m_info(resultData.databaseInfo())
     , m_databaseConnectionIdentifier(resultData.databaseConnectionIdentifier())
 {
-    LOG(IndexedDB, "IDBDatabase::IDBDatabase - Creating database %s with version %" PRIu64 " connection %" PRIu64, m_info.name().utf8().data(), m_info.version(), m_databaseConnectionIdentifier);
+    LOG(IndexedDB, "IDBDatabase::IDBDatabase - Creating database %s with version %" PRIu64 " connection %" PRIu64 " (%p)", m_info.name().utf8().data(), m_info.version(), m_databaseConnectionIdentifier, this);
     suspendIfNeeded();
     m_connectionProxy->registerDatabaseConnection(*this);
 }
@@ -63,6 +63,10 @@ IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnecti
 IDBDatabase::~IDBDatabase()
 {
     ASSERT(currentThread() == originThreadID());
+
+    if (!m_closedInServer)
+        m_connectionProxy->databaseConnectionClosed(*this);
+
     m_connectionProxy->unregisterDatabaseConnection(*this);
 }
 
@@ -460,7 +464,7 @@ void IDBDatabase::didCommitOrAbortTransaction(IDBTransaction& transaction)
 void IDBDatabase::fireVersionChangeEvent(const IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion)
 {
     uint64_t currentVersion = m_info.version();
-    LOG(IndexedDB, "IDBDatabase::fireVersionChangeEvent - current version %" PRIu64 ", requested version %" PRIu64 ", connection %" PRIu64, currentVersion, requestedVersion, m_databaseConnectionIdentifier);
+    LOG(IndexedDB, "IDBDatabase::fireVersionChangeEvent - current version %" PRIu64 ", requested version %" PRIu64 ", connection %" PRIu64 " (%p)", currentVersion, requestedVersion, m_databaseConnectionIdentifier, this);
 
     ASSERT(currentThread() == originThreadID());
 
@@ -476,7 +480,7 @@ void IDBDatabase::fireVersionChangeEvent(const IDBResourceIdentifier& requestIde
 
 bool IDBDatabase::dispatchEvent(Event& event)
 {
-    LOG(IndexedDB, "IDBDatabase::dispatchEvent (%" PRIu64 ")", m_databaseConnectionIdentifier);
+    LOG(IndexedDB, "IDBDatabase::dispatchEvent (%" PRIu64 ") (%p)", m_databaseConnectionIdentifier, this);
     ASSERT(currentThread() == originThreadID());
 
     bool result = EventTargetWithInlineData::dispatchEvent(event);
index 4d93834..70466a1 100644 (file)
@@ -77,7 +77,7 @@ void IDBConnectionToServer::didDeleteDatabase(const IDBResultData& resultData)
 
 void IDBConnectionToServer::openDatabase(const IDBRequestData& request)
 {
-    LOG(IndexedDB, "IDBConnectionToServer::openDatabase - %s (%" PRIu64 ")", request.databaseIdentifier().debugString().utf8().data(), request.requestedVersion());
+    LOG(IndexedDB, "IDBConnectionToServer::openDatabase - %s (%s) (%" PRIu64 ")", request.databaseIdentifier().debugString().utf8().data(), request.requestIdentifier().loggingString().utf8().data(), request.requestedVersion());
     m_delegate->openDatabase(request);
 }