Bug 1470306 - More assertions in MessagePort, r=qdot a=ritu DEVEDITION_62_0b14_BUILD1 DEVEDITION_62_0b14_RELEASE FIREFOX_62_0b14_BUILD1 FIREFOX_62_0b14_RELEASE
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 24 Jul 2018 09:29:51 +0200
changeset 480732 3a3725e292e129729b50c60989a4e2012cf8112a
parent 480731 fb00c69a67877caee3c40d523b467ac87784b694
child 480733 b9421bf289262721cff74f760e2fd40040f973df
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, ritu
bugs1470306
milestone62.0
Bug 1470306 - More assertions in MessagePort, r=qdot a=ritu Still trying to understand why we have MessagePort::CloseInternal crashes, here I introduce more assertions and a security check in case PBackground initialization fails.
dom/messagechannel/MessagePort.cpp
--- a/dom/messagechannel/MessagePort.cpp
+++ b/dom/messagechannel/MessagePort.cpp
@@ -241,18 +241,18 @@ MessagePort::Create(nsIGlobalObject* aGl
                  aIdentifier.sequenceId(), aIdentifier.neutered(),
                  eStateEntangling, aRv);
   return mp.forget();
 }
 
 void
 MessagePort::UnshippedEntangle(MessagePort* aEntangledPort)
 {
-  MOZ_ASSERT(aEntangledPort);
-  MOZ_ASSERT(!mUnshippedEntangledPort);
+  MOZ_DIAGNOSTIC_ASSERT(aEntangledPort);
+  MOZ_DIAGNOSTIC_ASSERT(!mUnshippedEntangledPort);
 
   mUnshippedEntangledPort = aEntangledPort;
 }
 
 void
 MessagePort::Initialize(const nsID& aUUID,
                         const nsID& aDestinationUUID,
                         uint32_t aSequenceID, bool aNeutered,
@@ -292,16 +292,18 @@ MessagePort::Initialize(const nsID& aUUI
 
     // When the callback is executed, we cannot process messages anymore because
     // we cannot dispatch new runnables. Let's force a Close().
     RefPtr<StrongWorkerRef> strongWorkerRef =
       StrongWorkerRef::Create(workerPrivate, "MessagePort",
                               [self]() { self->CloseForced(); });
     if (NS_WARN_IF(!strongWorkerRef)) {
       // The worker is shutting down.
+      mState = eStateDisentangled;
+      UpdateMustKeepAlive();
       aRv.Throw(NS_ERROR_FAILURE);
       return;
     }
 
     MOZ_ASSERT(!mWorkerRef);
     mWorkerRef = std::move(strongWorkerRef);
   }
 }
@@ -373,17 +375,17 @@ MessagePort::PostMessage(JSContext* aCx,
 
   // This message has to be ignored.
   if (mState > eStateEntangled) {
     return;
   }
 
   // If we are unshipped we are connected to the other port on the same thread.
   if (mState == eStateUnshippedEntangled) {
-    MOZ_ASSERT(mUnshippedEntangledPort);
+    MOZ_DIAGNOSTIC_ASSERT(mUnshippedEntangledPort);
     mUnshippedEntangledPort->mMessages.AppendElement(data);
     mUnshippedEntangledPort->Dispatch();
     return;
   }
 
   // Not entangled yet, but already closed/disentangled.
   if (mState == eStateEntanglingForDisentangle ||
       mState == eStateEntanglingForClose) {