Bug 1690370 - Remove race condition on BodyConsumer::mShuttingDown r=dom-worker-reviewers,sg
authorEden Chuang <echuang@mozilla.com>
Wed, 10 Feb 2021 18:34:40 +0000
changeset 566868 b4948157d9613ee528a624af4bd0521674ea0dbd
parent 566867 6ca1de7bf8a613f667098874cee78e516ad267ed
child 566869 6aee476f800f45afcd8c956972c54d7c919b6b0a
push id38191
push userbtara@mozilla.com
push dateThu, 11 Feb 2021 05:02:45 +0000
treeherdermozilla-central@5cbcb80f72bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-worker-reviewers, sg
bugs1690370
milestone87.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1690370 - Remove race condition on BodyConsumer::mShuttingDown r=dom-worker-reviewers,sg According to [[ https://searchfox.org/mozilla-central/rev/7067bbd8194f4346ec59d77c33cd88f06763e090/dom/base/BodyConsumer.h#132 | the comment on BodyConsumer::mShuttingDown declaration]], it is designed to be accessed on the main thread only. However, the [[ https://searchfox.org/mozilla-central/rev/7067bbd8194f4346ec59d77c33cd88f06763e090/dom/base/BodyConsumer.cpp#299-304 | callback of StrongWorkerRef::Create in BodyConsumer::Create ]] could access BodyConsumer::mShuttingDown on any thread. The patch removes the direct accessing the mShuttingDown in the callback since calling BodyConsumer::ShutDownMainThreadConsuming() will set mShuttingDown as true. Differential Revision: https://phabricator.services.mozilla.com/D104528
dom/base/BodyConsumer.cpp
--- a/dom/base/BodyConsumer.cpp
+++ b/dom/base/BodyConsumer.cpp
@@ -294,17 +294,16 @@ NS_IMPL_ISUPPORTS(ConsumeBodyDoneObserve
   if (!NS_IsMainThread()) {
     WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
     MOZ_ASSERT(workerPrivate);
 
     RefPtr<StrongWorkerRef> strongWorkerRef =
         StrongWorkerRef::Create(workerPrivate, "BodyConsumer", [consumer]() {
           consumer->mConsumePromise = nullptr;
           consumer->mBodyConsumed = true;
-          consumer->mShuttingDown = true;
           consumer->ReleaseObject();
           consumer->ShutDownMainThreadConsuming();
         });
     if (NS_WARN_IF(!strongWorkerRef)) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }