From a3feed4a33d4c8ba27efe03ebba569bcf2ce349f Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Thu, 13 Jun 2013 12:24:49 -0400 Subject: [PATCH] bug 881643 unhandled sync OnInputStreamReady on AsyncWait stack r=hurley --- netwerk/base/src/nsSocketTransport2.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/netwerk/base/src/nsSocketTransport2.cpp b/netwerk/base/src/nsSocketTransport2.cpp index 64cb886651c..1ab1c4327d5 100644 --- a/netwerk/base/src/nsSocketTransport2.cpp +++ b/netwerk/base/src/nsSocketTransport2.cpp @@ -410,10 +410,7 @@ nsSocketInputStream::AsyncWait(nsIInputStreamCallback *callback, { SOCKET_LOG(("nsSocketInputStream::AsyncWait [this=%p]\n", this)); - // This variable will be non-null when we want to call the callback - // directly from this function, but outside the lock. - // (different from callback when target is not null) - nsCOMPtr directCallback; + bool hasError = false; { MutexAutoLock lock(mTransport->mLock); @@ -425,16 +422,20 @@ nsSocketInputStream::AsyncWait(nsIInputStreamCallback *callback, } else mCallback = callback; + mCallbackFlags = flags; - if (NS_FAILED(mCondition)) - directCallback.swap(mCallback); - else - mCallbackFlags = flags; - } - if (directCallback) - directCallback->OnInputStreamReady(this); - else + hasError = NS_FAILED(mCondition); + } // unlock mTransport->mLock + + if (hasError) { + // OnSocketEvent will call OnInputStreamReady with an error code after + // going through the event loop. We do this because most socket callers + // do not expect AsyncWait() to synchronously execute the OnInputStreamReady + // callback. + mTransport->PostEvent(nsSocketTransport::MSG_INPUT_PENDING); + } else { mTransport->OnInputPending(); + } return NS_OK; }