Repository navigation
Conversation
…ence its loader rdar://188341702 https://bugs.webkit.org/show_bug.cgi?id=327816 Reviewed by NOBODY (OOPS!). NetworkResourceLoader can race the service worker fetch with the network. In case of redirection for a navigation load, we might receive the network redirection before the service worker answer. In that case, NetworkResourceLoader would set its service worker task to null and would either create a new one directly or would restart the load. That makes the NetworkResourceLoader forgetting about the service worker task. If NetworkResourceLoader dies, the service worker fetch task might start when its context connection is created and would crash. To prevent this, we make sure to cancel the service worker fetch task when NetworkResourceLoader is no longer interested in it. We do this in NetworkResourceLoader::continueWillSendRequest and for good measure, we also do this in NetworkResourceLoader::~NetworkResourceLoader. While writing the test, we hit an issue with an ASSERT in SWServerWorker::setWorkerScripts. This happens as the test is trying to create several fetch events on the same service worker that is not yet running. We would then load scripts for every of these fetch events, which is unnecessary. To prevent this, we introduce a HashMap of the workers whose scripts are being loaded. We store the callbacks to call when the scripts are loaded. If a worker is already in this HashMap, it means that scripts are being loaded and we do not need to request the store to load them again. Test: http/wpt/service-workers/service-worker-fetch-task-cancel-on-redirect.https.html * LayoutTests/http/wpt/service-workers/resources/redirect.py: Added. * LayoutTests/http/wpt/service-workers/service-worker-fetch-task-cancel-on-redirect.https-expected.txt: Added. * LayoutTests/http/wpt/service-workers/service-worker-fetch-task-cancel-on-redirect.https.html: Added. * Source/WebCore/workers/service/server/SWServer.cpp: (WebCore::SWServer::close): (WebCore::SWServer::loadWorkerScripts): * Source/WebCore/workers/service/server/SWServer.h: * Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp: (WebKit::NetworkResourceLoader::continueWillSendRequest): * Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp: (WebKit::ServiceWorkerFetchTask::start): (WebKit::ServiceWorkerFetchTask::startFetch):
…s don https://bugs.webkit.org/show_bug.cgi?id=327822 rdar://problem/190211445 Reviewed by NOBODY (OOPS!). We want to align NetworkResourceLoader handling of m_serviceWorkerFetchTask with m_networkLoad. For that reason, we are now cancelling/nullifying m_serviceWorkerFetchTask in NetworkResourceLoader::cleanup. Given there are some async callbacks (content filtering for instance), to ensure that we do not restart either network loads or service worker tasks after the NetworkResourceLoader has been cleaned up, we add NetworkResourceLoader::m_isDone and set it to true in NetworkResourceLoader::cleanup. We use it in NetworkResourceLoader::continueWillSendRequest and NetworkResourceLoader::startWithServiceWorker to check at async return time whether we should continue. As a strengthening, we update ServiceWorkerFetchTask to include more m_isDone checks so that we do not create reentrancy potential issues. Covered by existing tests. * Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp: (WebKit::NetworkResourceLoader::~NetworkResourceLoader): (WebKit::NetworkResourceLoader::cleanup): (WebKit::NetworkResourceLoader::convertToDownload): (WebKit::NetworkResourceLoader::abort): (WebKit::NetworkResourceLoader::continueWillSendRequest): (WebKit::NetworkResourceLoader::startWithServiceWorker): * Source/WebKit/NetworkProcess/NetworkResourceLoader.h: * Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerFetchTask.cpp: (WebKit::ServiceWorkerFetchTask::didFinish): (WebKit::ServiceWorkerFetchTask::didFail):
Collaborator
|
EWS run on current version of this PR (hash 2172873) Details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
2172873
2172873