Bug 1576183 - Don't access worker promise if already shutdown r=baku

The reason of the assertion failure is that WorkerFetchResolver::Shutdown is already called, but we still call WorkerRun from WorkerFetchResponseEndRunnable::Cancel [1].
This patch adds a flag mIsShutdown to avoid doing WorkerRun if mIsShutdown is true.


[1] https://searchfox.org/mozilla-central/rev/325c1a707819602feff736f129cb36055ba6d94f/dom/fetch/Fetch.cpp#733

Differential Revision: https://phabricator.services.mozilla.com/D43777

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kershaw Chang 2019-08-28 20:21:50 +00:00
Родитель 2d7dcc352d
Коммит 07b1d8bc29
1 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -186,6 +186,7 @@ class WorkerFetchResolver final : public FetchDriverObserver {
// Touched only on the worker thread.
RefPtr<FetchObserver> mFetchObserver;
RefPtr<WeakWorkerRef> mWorkerRef;
bool mIsShutdown;
public:
// Returns null if worker is shutting down.
@ -248,6 +249,7 @@ class WorkerFetchResolver final : public FetchDriverObserver {
Promise* WorkerPromise(WorkerPrivate* aWorkerPrivate) const {
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
MOZ_ASSERT(!mIsShutdown);
return mPromiseProxy->WorkerPromise();
}
@ -271,6 +273,7 @@ class WorkerFetchResolver final : public FetchDriverObserver {
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
mIsShutdown = true;
mPromiseProxy->CleanUp();
mFetchObserver = nullptr;
@ -282,12 +285,19 @@ class WorkerFetchResolver final : public FetchDriverObserver {
mWorkerRef = nullptr;
}
bool IsShutdown(WorkerPrivate* aWorkerPrivate) const {
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
return mIsShutdown;
}
private:
WorkerFetchResolver(PromiseWorkerProxy* aProxy,
AbortSignalProxy* aSignalProxy, FetchObserver* aObserver)
: mPromiseProxy(aProxy),
mSignalProxy(aSignalProxy),
mFetchObserver(aObserver) {
mFetchObserver(aObserver),
mIsShutdown(false) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(mPromiseProxy);
}
@ -718,6 +728,10 @@ class WorkerFetchResponseEndRunnable final : public MainThreadWorkerRunnable,
mReason(aReason) {}
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override {
if (mResolver->IsShutdown(aWorkerPrivate)) {
return true;
}
if (mReason == FetchDriverObserver::eAborted) {
mResolver->WorkerPromise(aWorkerPrivate)
->MaybeReject(NS_ERROR_DOM_ABORT_ERR);