Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 95f161190996936606fdf875b3d25a1f61639234
      
https://github.com/WebKit/WebKit/commit/95f161190996936606fdf875b3d25a1f61639234
  Author: Sihui Liu <[email protected]>
  Date:   2024-11-15 (Fri, 15 Nov 2024)

  Changed paths:
    M Source/WebKit/NetworkProcess/cache/NetworkCache.cpp
    M Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp
    M Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp
    M Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h

  Log Message:
  -----------
  Ensure usage of ReadOperation is thread-safe
https://bugs.webkit.org/show_bug.cgi?id=282994
rdar://139734750

Reviewed by Ben Nham.

NetworkCache::Storage::ReadOperation is not thread-safe. However, 
NetworkCache::Storage is accessing ReadOperation and
its members directly from different threads; see Storage::dispatchReadOperation 
for an example. This existing usage
is error-prone and could lead to unexpected results, like the issue 286129@main 
fixed. To make it more robust, this
patch makes a few changes:
1. Ensure ReadOperation is only accessed from main thread. The background 
threads only get identifier of ReadOperation,
and file paths. When they complete tasks to read and parse file data, they send 
back the identifier and results back to
main thread, and main thread will finish operation.
2. Make ReadOperation not hold strong reference to Storage and capture the 
reference in tasks instead.
3. Make ReadOperation class instead of struct, so that access to members needs 
to be done via member functions, which
have threading assertion.
4. Stop using unique_ptr for Record, so it's easier to remember to do isolated 
copy when passing it across threads.

* Source/WebKit/NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::retrieve):
* Source/WebKit/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveEntryFromStorage):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
* Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::ReadOperation::ReadOperation):
(WebKit::NetworkCache::Storage::ReadOperation::identifier const):
(WebKit::NetworkCache::Storage::ReadOperation::key const):
(WebKit::NetworkCache::Storage::ReadOperation::priority const):
(WebKit::NetworkCache::Storage::ReadOperation::isCanceled const):
(WebKit::NetworkCache::Storage::ReadOperation::canFinish const):
(WebKit::NetworkCache::Storage::ReadOperation::setWaitsForBlob):
(WebKit::NetworkCache::Storage::isHigherPriority):
(WebKit::NetworkCache::Storage::ReadOperation::updateForStart):
(WebKit::NetworkCache::Storage::ReadOperation::updateForDispatch):
(WebKit::NetworkCache::Storage::ReadOperation::cancel):
(WebKit::NetworkCache::Storage::ReadOperation::finish):
(WebKit::NetworkCache::Storage::ReadOperation::finishReadRecord):
(WebKit::NetworkCache::Storage::ReadOperation::finishReadBlob):
(WebKit::NetworkCache::Storage::readRecord):
(WebKit::NetworkCache::Storage::dispatchReadOperation):
(WebKit::NetworkCache::Storage::readRecordFromData):
(WebKit::NetworkCache::Storage::readBlobIfNecessary):
(WebKit::NetworkCache::Storage::finishReadOperation):
(WebKit::NetworkCache::Storage::cancelAllReadOperations):
(WebKit::NetworkCache::retrieveFromMemory):
(WebKit::NetworkCache::Storage::retrieve):
(WebKit::NetworkCache::nextReadOperationOrdinal): Deleted.
* Source/WebKit/NetworkProcess/cache/NetworkCacheStorage.h:
(WebKit::NetworkCache::Storage::Record::Record):
(WebKit::NetworkCache::Storage::Record::isNull const):

Canonical link: https://commits.webkit.org/286646@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to