Skip to content

Commit

Permalink
Bug 1686154 - Fix the race condition on WorkerFetchResolver::mFetchOb…
Browse files Browse the repository at this point in the history
…server. r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D111525
  • Loading branch information
edenchuang committed Apr 13, 2021
1 parent 822fc2a commit 2afeed0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 6 additions & 3 deletions dom/fetch/Fetch.cpp
Expand Up @@ -266,6 +266,8 @@ class WorkerFetchResolver final : public FetchDriverObserver {
RefPtr<WeakWorkerRef> mWorkerRef;
bool mIsShutdown;

Atomic<bool> mNeedOnDataAvailable;

public:
// Returns null if worker is shutting down.
static already_AddRefed<WorkerFetchResolver> Create(
Expand Down Expand Up @@ -354,6 +356,7 @@ class WorkerFetchResolver final : public FetchDriverObserver {
mIsShutdown = true;
mPromiseProxy->CleanUp();

mNeedOnDataAvailable = false;
mFetchObserver = nullptr;

if (mSignalProxy) {
Expand All @@ -376,7 +379,8 @@ class WorkerFetchResolver final : public FetchDriverObserver {
: mPromiseProxy(aProxy),
mSignalProxy(aSignalProxy),
mFetchObserver(aObserver),
mIsShutdown(false) {
mIsShutdown(false),
mNeedOnDataAvailable(!!aObserver) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(mPromiseProxy);
}
Expand Down Expand Up @@ -871,8 +875,7 @@ void WorkerFetchResolver::OnResponseAvailableInternal(

bool WorkerFetchResolver::NeedOnDataAvailable() {
AssertIsOnMainThread();
MutexAutoLock lock(mPromiseProxy->Lock());
return !!mFetchObserver;
return mNeedOnDataAvailable;
}

void WorkerFetchResolver::OnDataAvailable() {
Expand Down
2 changes: 0 additions & 2 deletions dom/promise/Promise.cpp
Expand Up @@ -806,8 +806,6 @@ void PromiseWorkerProxy::CleanUp() {
// Release the Promise and remove the PromiseWorkerProxy from the holders of
// the worker thread since the Promise has been resolved/rejected or the
// worker thread has been cancelled.
mWorkerRef = nullptr;

CleanProperties();
}
Release();
Expand Down

0 comments on commit 2afeed0

Please sign in to comment.