From c77444b2ef4d1362da054a36bf44d971719d027d Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Sun, 24 Jan 2016 17:31:11 -0800 Subject: [PATCH] Bug 1240985 - Back out "Stop returning MsgNotAllowed" patch. --- ipc/glue/MessageChannel.cpp | 19 ++++++++++++++++++- ipc/glue/MessageChannel.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ipc/glue/MessageChannel.cpp b/ipc/glue/MessageChannel.cpp index 26b1a8a061c..0cd2bb16a0b 100644 --- a/ipc/glue/MessageChannel.cpp +++ b/ipc/glue/MessageChannel.cpp @@ -324,6 +324,7 @@ MessageChannel::MessageChannel(MessageListener *aListener) mDispatchingAsyncMessagePriority(0), mCurrentTransaction(0), mTimedOutMessageSeqno(0), + mTimedOutMessagePriority(0), mRecvdErrors(0), mRemoteStackDepthGuess(false), mSawInterruptOutMsg(false), @@ -1039,6 +1040,7 @@ MessageChannel::Send(Message* aMsg, Message* aReply) } mTimedOutMessageSeqno = seqno; + mTimedOutMessagePriority = prio; return false; } } @@ -1408,7 +1410,22 @@ MessageChannel::DispatchSyncMessage(const Message& aMsg, Message*& aReply) MessageChannel*& blockingVar = ShouldBlockScripts() ? gParentProcessBlocker : dummy; Result rv; - { + if (mTimedOutMessageSeqno && mTimedOutMessagePriority >= prio) { + // If the other side sends a message in response to one of our messages + // that we've timed out, then we reply with an error. + // + // We do this because want to avoid a situation where we process an + // incoming message from the child here while it simultaneously starts + // processing our timed-out CPOW. It's very bad for both sides to + // be processing sync messages concurrently. + // + // The only exception is if the incoming message has urgent priority and + // our timed-out message had only high priority. In that case it's safe + // to process the incoming message because we know that the child won't + // process anything (the child will defer incoming messages when waiting + // for a response to its urgent message). + rv = MsgNotAllowed; + } else { AutoSetValue blocked(blockingVar, this); AutoSetValue sync(mDispatchingSyncMessage, true); AutoSetValue prioSet(mDispatchingSyncMessagePriority, prio); diff --git a/ipc/glue/MessageChannel.h b/ipc/glue/MessageChannel.h index f05eed9338d..72c25e12eae 100644 --- a/ipc/glue/MessageChannel.h +++ b/ipc/glue/MessageChannel.h @@ -630,6 +630,7 @@ class MessageChannel : HasResultCodes // hitting a lot of corner cases with message nesting that we don't really // care about. int32_t mTimedOutMessageSeqno; + int mTimedOutMessagePriority; // If waiting for the reply to a sync out-message, it will be saved here // on the I/O thread and then read and cleared by the worker thread.