Changeset 218516 in webkit


Ignore:
Timestamp:
Jun 19, 2017 4:19:11 PM (7 years ago)
Author:
beidson@apple.com
Message:

Various IndexedDB crashes as an after effect of previous test.
<rdar://problem/31418761> and https://bugs.webkit.org/show_bug.cgi?id=170436

Reviewed by Chris Dumez.

No new test (No consistent test possible, in practice covered by all existing IDB tests)

This is timing related, where a UniqueIDBDatabase can be destroyed on the main thread while
it still has one task left to try to execute on the IDBServer thread.

The background thread tasks don't Ref<> the UniqueIDBDatabase, so even though task execution
took a Ref<> protector, there was still a small window for a race.

Should be closed up by making the background thread tasks themselves protect this.

  • Modules/indexeddb/server/UniqueIDBDatabase.cpp:

(WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
(WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTaskReply):
(WebCore::IDBServer::UniqueIDBDatabase::executeNextDatabaseTask):
(WebCore::IDBServer::UniqueIDBDatabase::executeNextDatabaseTaskReply):

  • Modules/indexeddb/server/UniqueIDBDatabase.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r218511 r218516  
     12017-06-19  Brady Eidson  <beidson@apple.com>
     2
     3        Various IndexedDB crashes as an after effect of previous test.
     4        <rdar://problem/31418761> and https://bugs.webkit.org/show_bug.cgi?id=170436
     5
     6        Reviewed by Chris Dumez.
     7
     8        No new test (No consistent test possible, in practice covered by all existing IDB tests)
     9
     10        This is timing related, where a UniqueIDBDatabase can be destroyed on the main thread while
     11        it still has one task left to try to execute on the IDBServer thread.
     12       
     13        The background thread tasks don't Ref<> the UniqueIDBDatabase, so even though task execution
     14        took a Ref<> protector, there was still a small window for a race.
     15       
     16        Should be closed up by making the background thread tasks themselves protect this.
     17       
     18        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
     19        (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
     20        (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTaskReply):
     21        (WebCore::IDBServer::UniqueIDBDatabase::executeNextDatabaseTask):
     22        (WebCore::IDBServer::UniqueIDBDatabase::executeNextDatabaseTaskReply):
     23        * Modules/indexeddb/server/UniqueIDBDatabase.h:
     24
    1252017-06-19  Sam Weinig  <sam@webkit.org>
    226
  • trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp

    r218048 r218516  
    17071707void UniqueIDBDatabase::postDatabaseTask(CrossThreadTask&& task)
    17081708{
    1709     m_databaseQueue.append(WTFMove(task));
     1709    m_databaseQueue.append([protectedThis = makeRef(*this), task = WTFMove(task)]() mutable {
     1710        task.performTask();
     1711    });
    17101712    ++m_queuedTaskCount;
    17111713
     
    17161718{
    17171719    ASSERT(!isMainThread());
    1718     m_databaseReplyQueue.append(WTFMove(task));
     1720
     1721    m_databaseReplyQueue.append([protectedThis = makeRef(*this), task = WTFMove(task)]() mutable {
     1722        task.performTask();
     1723    });
    17191724    ++m_queuedTaskCount;
    17201725
     
    17301735    ASSERT(task);
    17311736
    1732     // Performing the task might end up removing the last reference to this.
    1733     Ref<UniqueIDBDatabase> protectedThis(*this);
    1734 
    1735     task->performTask();
     1737    (*task)();
    17361738    --m_queuedTaskCount;
    17371739
    1738     // Release the ref in the main thread to ensure it's deleted there as expected in case of being the last reference.
    1739     callOnMainThread([protectedThis = WTFMove(protectedThis)] {
     1740    // Release the task on the main thread in case it holds the last reference to this,
     1741    // as UniqueIDBDatabase objects must be deleted on the main thread.
     1742    callOnMainThread([task = WTFMove(task)] {
    17401743    });
    17411744}
     
    17491752    ASSERT(task);
    17501753
    1751     // Performing the task might end up removing the last reference to this.
    1752     Ref<UniqueIDBDatabase> protectedThis(*this);
    1753 
    1754     task->performTask();
     1754    (*task)();
    17551755    --m_queuedTaskCount;
    17561756
  • trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h

    r218048 r218516  
    267267    bool m_deleteBackingStoreInProgress { false };
    268268
    269     CrossThreadQueue<CrossThreadTask> m_databaseQueue;
    270     CrossThreadQueue<CrossThreadTask> m_databaseReplyQueue;
     269    CrossThreadQueue<Function<void ()>> m_databaseQueue;
     270    CrossThreadQueue<Function<void ()>> m_databaseReplyQueue;
    271271    std::atomic<uint64_t> m_queuedTaskCount { 0 };
    272272
Note: See TracChangeset for help on using the changeset viewer.