Skip to content

Commit

Permalink
Bug 1819496 - Making FetchParent::mResponsePromises be only accessed …
Browse files Browse the repository at this point in the history
…on the main thread. r=asuth

FetchParent::mResponsePromises should only be accessed/assigned on the main thread.

This patch makes the ResponseEndPromsie callbacks run on the main thread.

https://searchfox.org/mozilla-central/rev/3002762e41363de8ee9ca80196d55e79651bcb6b/dom/fetch/FetchParent.cpp#178-191

Such that there would not be a race on FetchParent::mResponsePromises.

Differential Revision: https://phabricator.services.mozilla.com/D171848
  • Loading branch information
edenchuang committed Mar 8, 2023
1 parent 3388de5 commit cb4bc9e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dom/fetch/FetchParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "FetchService.h"
#include "InternalRequest.h"
#include "InternalResponse.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/ClientInfo.h"
#include "mozilla/dom/FetchTypes.h"
Expand Down Expand Up @@ -176,23 +175,23 @@ IPCResult FetchParent::RecvFetchOp(FetchOpArgs&& aArgs) {
self->mID})));

self->mResponsePromises->GetResponseEndPromise()->Then(
self->mBackgroundEventTarget, __func__,
GetMainThreadSerialEventTarget(), __func__,
[self](ResponseEndArgs&& aArgs) mutable {
AssertIsOnMainThread();
MOZ_ASSERT(self->mPromise);
self->mPromise->Resolve(true, __func__);
self->mResponsePromises = nullptr;
self->mPromise = nullptr;
},
[self](CopyableErrorResult&& aErr) mutable {
AssertIsOnMainThread();
MOZ_ASSERT(self->mPromise);
self->mPromise->Reject(aErr.StealNSResult(), __func__);
self->mResponsePromises = nullptr;
self->mPromise = nullptr;
});
});

MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
NS_DispatchToMainThread(r.forget(), nsIThread::DISPATCH_NORMAL));

return IPC_OK();
}
Expand All @@ -217,8 +216,9 @@ IPCResult FetchParent::RecvAbortFetchOp() {
fetchService->CancelFetch(std::move(self->mResponsePromises));
}
});

MOZ_ALWAYS_SUCCEEDS(
SchedulerGroup::Dispatch(TaskCategory::Other, r.forget()));
NS_DispatchToMainThread(r.forget(), nsIThread::DISPATCH_NORMAL));

return IPC_OK();
}
Expand Down

0 comments on commit cb4bc9e

Please sign in to comment.