⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 278179 in webkit


Ignore:
Timestamp:
May 27, 2021, 2:55:40 PM (5 years ago)
Author:
sihui_liu@apple.com
Message:

Abandon pending tasks on background thread when WebIDBServer is closed
https://bugs.webkit.org/show_bug.cgi?id=226295

Reviewed by Chris Dumez.

Source/WebCore:

  • Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: Disable threading check as we may

abort transactions on the main thread.
(WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):

Source/WebKit:

When WebIDBServer is closed, it means there is no open connection to client, so we don't need to handle pending
tasks. We can ditch them by killing the CrossThreadQueue. For ongoing task, it can be blocked on quota check, so
let's just stop database activities on the main thread to make sure database lock is released.

  • NetworkProcess/IndexedDB/WebIDBServer.cpp:

(WebKit::WebIDBServer::close):

  • NetworkProcess/IndexedDB/WebIDBServer.h:

Source/WTF:

Make the wait end with either a new message or queue being killed.

  • wtf/CrossThreadQueue.h:

(WTF::CrossThreadQueue<DataType>::waitForMessage):

  • wtf/CrossThreadTask.h:

(WTF::CrossThreadTask::operator bool const):

  • wtf/CrossThreadTaskHandler.cpp:

(WTF::CrossThreadTaskHandler::taskRunLoop):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r278178 r278179  
     12021-05-27  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Abandon pending tasks on background thread when WebIDBServer is closed
     4        https://bugs.webkit.org/show_bug.cgi?id=226295
     5
     6        Reviewed by Chris Dumez.
     7
     8        Make the wait end with either a new message or queue being killed.
     9
     10        * wtf/CrossThreadQueue.h:
     11        (WTF::CrossThreadQueue<DataType>::waitForMessage):
     12        * wtf/CrossThreadTask.h:
     13        (WTF::CrossThreadTask::operator bool const):
     14        * wtf/CrossThreadTaskHandler.cpp:
     15        (WTF::CrossThreadTaskHandler::taskRunLoop):
     16
    1172021-05-27  Don Olmstead  <don.olmstead@sony.com>
    218
  • trunk/Source/WTF/wtf/CrossThreadQueue.h

    r277958 r278179  
    7474
    7575    auto found = m_queue.end();
    76     while (found == m_queue.end()) {
     76    while (!m_killed && found == m_queue.end()) {
    7777        found = m_queue.begin();
    7878        if (found != m_queue.end())
  • trunk/Source/WTF/wtf/CrossThreadTask.h

    r248546 r278179  
    4949        m_taskFunction();
    5050    }
     51
     52    explicit operator bool() const { return !!m_taskFunction; }
    5153
    5254protected:
  • trunk/Source/WTF/wtf/CrossThreadTaskHandler.cpp

    r277847 r278179  
    7575    }
    7676
    77     while (!m_taskQueue.isKilled()) {
     77    while (auto task = m_taskQueue.waitForMessage()) {
    7878        std::unique_ptr<AutodrainedPool> autodrainedPool = (m_useAutodrainedPool == AutodrainedPoolForRunLoop::Use) ? makeUnique<AutodrainedPool>() : nullptr;
    7979
    80         m_taskQueue.waitForMessage().performTask();
     80        task.performTask();
    8181    }
    8282}
  • trunk/Source/WebCore/ChangeLog

    r278175 r278179  
     12021-05-27  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Abandon pending tasks on background thread when WebIDBServer is closed
     4        https://bugs.webkit.org/show_bug.cgi?id=226295
     5
     6        Reviewed by Chris Dumez.
     7
     8        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp: Disable threading check as we may
     9        abort transactions on the main thread.
     10        (WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):
     11
    1122021-05-27  Wenson Hsieh  <wenson_hsieh@apple.com>
    213
  • trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp

    r278150 r278179  
    10051005        return IDBError { UnknownError, "Unable to open database file on disk"_s };
    10061006
     1007    m_sqliteDB->disableThreadingChecks();
    10071008    m_sqliteDB->enableAutomaticWALTruncation();
    10081009
  • trunk/Source/WebKit/ChangeLog

    r278176 r278179  
     12021-05-27  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Abandon pending tasks on background thread when WebIDBServer is closed
     4        https://bugs.webkit.org/show_bug.cgi?id=226295
     5
     6        Reviewed by Chris Dumez.
     7
     8        When WebIDBServer is closed, it means there is no open connection to client, so we don't need to handle pending
     9        tasks. We can ditch them by killing the CrossThreadQueue. For ongoing task, it can be blocked on quota check, so
     10        let's just stop database activities on the main thread to make sure database lock is released.
     11
     12        * NetworkProcess/IndexedDB/WebIDBServer.cpp:
     13        (WebKit::WebIDBServer::close):
     14        * NetworkProcess/IndexedDB/WebIDBServer.h:
     15
    1162021-05-27  Alex Christensen  <achristensen@webkit.org>
    217
  • trunk/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp

    r277943 r278179  
    416416        connection->removeThreadMessageReceiver(Messages::WebIDBServer::messageReceiverName());
    417417
    418     CrossThreadTaskHandler::setCompletionCallback([protectedThis = makeRef(*this)]() mutable {
    419         ASSERT(!RunLoop::isMain());
    420         callOnMainRunLoop([protectedThis = WTFMove(protectedThis)]() mutable { });
    421     });
    422 
    423     postTask([this]() mutable {
     418    CrossThreadTaskHandler::setCompletionCallback([this, protectedThis = makeRef(*this)]() mutable {
     419        ASSERT(!RunLoop::isMain());
     420
    424421        m_connectionMap.clear();
    425 
    426422        Locker locker { m_serverLock };
    427423        m_server = nullptr;
    428         CrossThreadTaskHandler::kill();
    429     });
     424
     425        callOnMainRunLoop([protectedThis = WTFMove(protectedThis)] { });
     426    });
     427
     428    {
     429        Locker locker { m_serverLock };
     430        if (m_server)
     431            m_server->stopDatabaseActivitiesOnMainThread();
     432    }
     433
     434    CrossThreadTaskHandler::kill();
    430435
    431436    m_closeCallback();
  • trunk/Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.h

    r275891 r278179  
    9999
    100100    Lock m_serverLock;
    101     std::unique_ptr<WebCore::IDBServer::IDBServer> m_server;
     101    std::unique_ptr<WebCore::IDBServer::IDBServer> m_server WTF_GUARDED_BY_LOCK(m_serverLock);
    102102    bool m_isSuspended { false };
    103103
Note: See TracChangeset for help on using the changeset viewer.