Changeset 241967 in webkit


Ignore:
Timestamp:
Feb 22, 2019 3:41:16 PM (5 years ago)
Author:
sihui_liu@apple.com
Message:

Crash under IDBServer::IDBConnectionToClient::identifier() const
https://bugs.webkit.org/show_bug.cgi?id=194843
<rdar://problem/48203102>

Reviewed by Geoffrey Garen.

UniqueIDBDatabase should ignore requests from connections that are already closed.

Tests are hard to create without some tricks on UniqueIDBDatabase so this fix is verified manually.
One test is created by adding delay to UniqueIDBDatabase::openBackingStore on the background thread to make sure
disconnection of web process happens before UniqueIDBDatabase::didOpenBackingStore, because didOpenBackingStore
may start a version change transaction and ask for identifier from the connection that is already gone.

  • Modules/indexeddb/server/IDBConnectionToClient.cpp:

(WebCore::IDBServer::IDBConnectionToClient::connectionToClientClosed):

  • Modules/indexeddb/server/IDBConnectionToClient.h:

(WebCore::IDBServer::IDBConnectionToClient::isClosed):

  • Modules/indexeddb/server/UniqueIDBDatabase.cpp:

(WebCore::IDBServer::UniqueIDBDatabase::clearStalePendingOpenDBRequests):
(WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
(WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r241949 r241967  
     12019-02-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Crash under IDBServer::IDBConnectionToClient::identifier() const
     4        https://bugs.webkit.org/show_bug.cgi?id=194843
     5        <rdar://problem/48203102>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        UniqueIDBDatabase should ignore requests from connections that are already closed.
     10
     11        Tests are hard to create without some tricks on UniqueIDBDatabase so this fix is verified manually.
     12        One test is created by adding delay to UniqueIDBDatabase::openBackingStore on the background thread to make sure
     13        disconnection of web process happens before UniqueIDBDatabase::didOpenBackingStore, because didOpenBackingStore
     14        may start a version change transaction and ask for identifier from the connection that is already gone.
     15
     16        * Modules/indexeddb/server/IDBConnectionToClient.cpp:
     17        (WebCore::IDBServer::IDBConnectionToClient::connectionToClientClosed):
     18        * Modules/indexeddb/server/IDBConnectionToClient.h:
     19        (WebCore::IDBServer::IDBConnectionToClient::isClosed):
     20        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
     21        (WebCore::IDBServer::UniqueIDBDatabase::clearStalePendingOpenDBRequests):
     22        (WebCore::IDBServer::UniqueIDBDatabase::handleDatabaseOperations):
     23        (WebCore::IDBServer::UniqueIDBDatabase::operationAndTransactionTimerFired):
     24        * Modules/indexeddb/server/UniqueIDBDatabase.h:
     25
    1262019-02-22  Wenson Hsieh  <wenson_hsieh@apple.com>
    227
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.cpp

    r239887 r241967  
    208208    }
    209209
     210    m_isClosed = true;
    210211    m_databaseConnections.clear();
    211212}
  • trunk/Source/WebCore/Modules/indexeddb/server/IDBConnectionToClient.h

    r239887 r241967  
    8080    void unregisterDatabaseConnection(UniqueIDBDatabaseConnection&);
    8181    void connectionToClientClosed();
    82 
     82    bool isClosed() { return m_isClosed; }
    8383private:
    8484    IDBConnectionToClient(IDBConnectionToClientDelegate&);
     
    8686    WeakPtr<IDBConnectionToClientDelegate> m_delegate;
    8787    HashSet<UniqueIDBDatabaseConnection*> m_databaseConnections;
     88    bool m_isClosed { false };
    8889};
    8990
  • trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp

    r241913 r241967  
    345345}
    346346
     347void UniqueIDBDatabase::clearStalePendingOpenDBRequests()
     348{
     349    while (!m_pendingOpenDBRequests.isEmpty() && m_pendingOpenDBRequests.first()->connection().isClosed())
     350        m_pendingOpenDBRequests.removeFirst();
     351}
     352
    347353void UniqueIDBDatabase::handleDatabaseOperations()
    348354{
     
    354360        return;
    355361
    356     if (m_versionChangeDatabaseConnection || m_versionChangeTransaction || m_currentOpenDBRequest) {
     362    clearStalePendingOpenDBRequests();
     363
     364    if (m_versionChangeDatabaseConnection || m_versionChangeTransaction || (m_currentOpenDBRequest && !m_currentOpenDBRequest->connection().isClosed())) {
    357365        // We can't start any new open-database operations right now, but we might be able to start handling a delete operation.
    358366        if (!m_currentOpenDBRequest && !m_pendingOpenDBRequests.isEmpty() && m_pendingOpenDBRequests.first()->isDeleteRequest())
     
    366374    }
    367375
    368     if (m_pendingOpenDBRequests.isEmpty())
    369         return;
     376    if (m_pendingOpenDBRequests.isEmpty()) {
     377        m_currentOpenDBRequest = nullptr;
     378        return;
     379    }
    370380
    371381    m_currentOpenDBRequest = m_pendingOpenDBRequests.takeFirst();
     
    15761586    // The current operation might require multiple attempts to handle, so try to
    15771587    // make further progress on it now.
    1578     if (m_currentOpenDBRequest)
     1588    if (m_currentOpenDBRequest && !m_currentOpenDBRequest->connection().isClosed())
    15791589        handleCurrentOperation();
    1580 
    1581     if (!m_currentOpenDBRequest)
     1590    else
    15821591        handleDatabaseOperations();
    15831592
  • trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h

    r241468 r241967  
    215215
    216216    bool prepareToFinishTransaction(UniqueIDBDatabaseTransaction&);
     217   
     218    void clearStalePendingOpenDBRequests();
    217219
    218220    void postDatabaseTask(CrossThreadTask&&);
Note: See TracChangeset for help on using the changeset viewer.