Skip to content

Commit

Permalink
Merge r242043 - IndexedDB: IDBDatabase and IDBTransaction are leaked …
Browse files Browse the repository at this point in the history
…in layout tests

https://bugs.webkit.org/show_bug.cgi?id=194709

Reviewed by Geoffrey Garen.

Source/WebCore:

When connection to IDB server is closed, IDBTransaction would abort without notifying IDBDatabase, so
IDBDatabase didn't clear its reference to IDBTransaction which created a reference cycle.

Also IDBTransaction didn't clear its reference to IDBRequest in this case and it led to another reference cycle
between IDBOpenDBRequest and IDBTransaction.

Test: storage/indexeddb/IDBObject-leak.html

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::connectionToServerLost):
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::~IDBTransaction):
(WebCore::IDBTransaction::connectionClosedFromServer):
* Modules/indexeddb/IDBTransaction.h:
* testing/Internals.cpp:
(WebCore::Internals::numberOfIDBTransactions const):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* TestExpectations:
* platform/wk2/TestExpectations:
* storage/indexeddb/IDBObject-leak-expected.txt: Added.
* storage/indexeddb/IDBObject-leak.html: Added.
  • Loading branch information
szewai authored and carlosgcampos committed Mar 5, 2019
1 parent 17f735c commit 49b3e93
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 2 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2019-02-25 Sihui Liu <sihui_liu@apple.com>

IndexedDB: IDBDatabase and IDBTransaction are leaked in layout tests
https://bugs.webkit.org/show_bug.cgi?id=194709

Reviewed by Geoffrey Garen.

* TestExpectations:
* platform/wk2/TestExpectations:
* storage/indexeddb/IDBObject-leak-expected.txt: Added.
* storage/indexeddb/IDBObject-leak.html: Added.

2019-02-22 Rob Buis <rbuis@igalia.com>

Fix unitless usage of mathsize
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/TestExpectations
Expand Up @@ -129,6 +129,7 @@ http/tests/storageAccess/ [ Skip ]
http/tests/navigation/process-swap-window-open.html [ Skip ]
http/tests/navigation/useragent-reload.php [ Skip ]
storage/indexeddb/modern/opendatabase-after-storage-crash.html [ Skip ]
storage/indexeddb/IDBObject-leak.html [ Skip ]
fast/forms/call-text-did-change-in-text-field-when-typing.html [ Skip ]

# Only Mac and iOS have an implementation of UIScriptController::doAsyncTask().
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/platform/wk2/TestExpectations
Expand Up @@ -746,6 +746,7 @@ http/wpt/cross-origin-resource-policy/ [ Pass ]

http/tests/navigation/useragent-reload.php [ Pass ]
storage/indexeddb/modern/opendatabase-after-storage-crash.html [ Pass ]
storage/indexeddb/IDBObject-leak.html [ Pass ]

fast/forms/call-text-did-change-in-text-field-when-typing.html [ Pass ]

Expand Down
10 changes: 10 additions & 0 deletions LayoutTests/storage/indexeddb/IDBObject-leak-expected.txt
@@ -0,0 +1,10 @@
This test verifies that IDBTransaction objects are freed.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS internals.numberOfIDBTransactions() is 0
PASS successfullyParsed is true

TEST COMPLETE

40 changes: 40 additions & 0 deletions LayoutTests/storage/indexeddb/IDBObject-leak.html
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
<script>
description('This test verifies that IDBTransaction objects are freed.');

jsTestIsAsync = true;

function test() {
if (!window.internals || !internals.numberOfIDBTransactions) {
testFailed('This test requires access to the Internals object');
finishJSTest();
return;
}

if (sessionStorage.doneFirstLoad) {
gc();
shouldBeEqualToNumber("internals.numberOfIDBTransactions()", 0);
finishJSTest();
return;
}

var dbname = setDBNameFromPath() + Date();
var request = window.indexedDB.open(dbname);
request.onupgradeneeded = function(evt) {
sessionStorage.doneFirstLoad = true;
if (!window.testRunner || !testRunner.terminateNetworkProcess) {
testFailed('This test requires access to the TestRunner object and terminateNetworkProcess() function');
finishJSTest();
return;
}
testRunner.terminateNetworkProcess();
setTimeout((()=> {
location.reload();
}), 0);
}
}

test();
</script>
27 changes: 27 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,30 @@
2019-02-25 Sihui Liu <sihui_liu@apple.com>

IndexedDB: IDBDatabase and IDBTransaction are leaked in layout tests
https://bugs.webkit.org/show_bug.cgi?id=194709

Reviewed by Geoffrey Garen.

When connection to IDB server is closed, IDBTransaction would abort without notifying IDBDatabase, so
IDBDatabase didn't clear its reference to IDBTransaction which created a reference cycle.

Also IDBTransaction didn't clear its reference to IDBRequest in this case and it led to another reference cycle
between IDBOpenDBRequest and IDBTransaction.

Test: storage/indexeddb/IDBObject-leak.html

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::connectionToServerLost):
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::~IDBTransaction):
(WebCore::IDBTransaction::connectionClosedFromServer):
* Modules/indexeddb/IDBTransaction.h:
* testing/Internals.cpp:
(WebCore::Internals::numberOfIDBTransactions const):
* testing/Internals.h:
* testing/Internals.idl:

2019-02-25 Charlie Turner <cturner@igalia.com>

[EME][GStreamer] Replace caps field loop with gst_structure_remove_fields
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Expand Up @@ -264,7 +264,8 @@ void IDBDatabase::connectionToServerLost(const IDBError& error)
m_closePending = true;
m_closedInServer = true;

for (auto& transaction : m_activeTransactions.values())
auto transactions = copyToVector(m_activeTransactions.values());
for (auto& transaction : transactions)
transaction->connectionClosedFromServer(error);

auto errorEvent = Event::create(m_eventNames.errorEvent, Event::CanBubble::Yes, Event::IsCancelable::No);
Expand Down
10 changes: 9 additions & 1 deletion Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Expand Up @@ -59,6 +59,8 @@
namespace WebCore {
using namespace JSC;

std::atomic<unsigned> IDBTransaction::numberOfIDBTransactions { 0 };

Ref<IDBTransaction> IDBTransaction::create(IDBDatabase& database, const IDBTransactionInfo& info)
{
return adoptRef(*new IDBTransaction(database, info, nullptr));
Expand All @@ -82,6 +84,8 @@ IDBTransaction::IDBTransaction(IDBDatabase& database, const IDBTransactionInfo&
LOG(IndexedDB, "IDBTransaction::IDBTransaction - %s", m_info.loggingString().utf8().data());
ASSERT(&m_database->originThread() == &Thread::current());

++numberOfIDBTransactions;

if (m_info.mode() == IDBTransactionMode::Versionchange) {
ASSERT(m_openDBRequest);
m_openDBRequest->setVersionChangeTransaction(*this);
Expand All @@ -105,6 +109,7 @@ IDBTransaction::IDBTransaction(IDBDatabase& database, const IDBTransactionInfo&

IDBTransaction::~IDBTransaction()
{
--numberOfIDBTransactions;
ASSERT(&m_database->originThread() == &Thread::current());
}

Expand Down Expand Up @@ -1434,7 +1439,8 @@ void IDBTransaction::connectionClosedFromServer(const IDBError& error)
{
LOG(IndexedDB, "IDBTransaction::connectionClosedFromServer - %s", error.message().utf8().data());

m_state = IndexedDB::TransactionState::Aborting;
m_database->willAbortTransaction(*this);
transitionedToFinishing(IndexedDB::TransactionState::Aborting);

abortInProgressOperations(error);

Expand All @@ -1445,6 +1451,7 @@ void IDBTransaction::connectionClosedFromServer(const IDBError& error)
ASSERT(m_transactionOperationsInProgressQueue.first() == operation.get());
operation->doComplete(IDBResultData::error(operation->identifier(), error));
}
m_currentlyCompletingRequest = nullptr;

connectionProxy().forgetActiveOperations(operations);

Expand All @@ -1454,6 +1461,7 @@ void IDBTransaction::connectionClosedFromServer(const IDBError& error)

m_idbError = error;
m_domError = error.toDOMException();
m_database->didAbortTransaction(*this);
fireOnAbort();
}

Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/Modules/indexeddb/IDBTransaction.h
Expand Up @@ -152,6 +152,8 @@ class IDBTransaction : public ThreadSafeRefCounted<IDBTransaction>, public Event

void visitReferencedObjectStores(JSC::SlotVisitor&) const;

WEBCORE_EXPORT static std::atomic<unsigned> numberOfIDBTransactions;

private:
IDBTransaction(IDBDatabase&, const IDBTransactionInfo&, IDBOpenDBRequest*);

Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/testing/Internals.cpp
Expand Up @@ -93,6 +93,8 @@
#include "HistoryController.h"
#include "HistoryItem.h"
#include "HitTestResult.h"
#include "IDBRequest.h"
#include "IDBTransaction.h"
#include "InspectorClient.h"
#include "InspectorController.h"
#include "InspectorFrontendClientLocal.h"
Expand Down Expand Up @@ -2383,6 +2385,11 @@ ExceptionOr<unsigned> Internals::countFindMatches(const String& text, const Vect
return document->page()->countFindMatches(text, parsedOptions.releaseReturnValue(), 1000);
}

unsigned Internals::numberOfIDBTransactions() const
{
return IDBTransaction::numberOfIDBTransactions;
}

unsigned Internals::numberOfLiveNodes() const
{
unsigned nodeCount = 0;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/testing/Internals.h
Expand Up @@ -379,6 +379,8 @@ class Internals final : public RefCounted<Internals>, private ContextDestruction
ExceptionOr<void> insertAuthorCSS(const String&) const;
ExceptionOr<void> insertUserCSS(const String&) const;

unsigned numberOfIDBTransactions() const;

unsigned numberOfLiveNodes() const;
unsigned numberOfLiveDocuments() const;
unsigned referencingNodeCount(const Document&) const;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/testing/Internals.idl
Expand Up @@ -406,6 +406,8 @@ enum CompositingPolicy {
void beginSimulatedMemoryPressure();
void endSimulatedMemoryPressure();

unsigned long numberOfIDBTransactions();

unsigned long numberOfLiveNodes();
unsigned long numberOfLiveDocuments();
unsigned long referencingNodeCount(Document document);
Expand Down

0 comments on commit 49b3e93

Please sign in to comment.