diff --git a/netwerk/base/src/nsSocketTransport2.cpp b/netwerk/base/src/nsSocketTransport2.cpp index 9e6988fb1758..62cb623f35a1 100644 --- a/netwerk/base/src/nsSocketTransport2.cpp +++ b/netwerk/base/src/nsSocketTransport2.cpp @@ -404,6 +404,10 @@ nsSocketInputStream::AsyncWait(nsIInputStreamCallback *callback, { LOG(("nsSocketInputStream::AsyncWait [this=%x]\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; { nsAutoLock lock(mTransport->mLock); @@ -423,9 +427,16 @@ nsSocketInputStream::AsyncWait(nsIInputStreamCallback *callback, else mCallback = callback; - mCallbackFlags = flags; + if (NS_FAILED(mCondition)) + directCallback.swap(mCallback); + else + mCallbackFlags = flags; } - mTransport->OnInputPending(); + if (directCallback) + directCallback->OnInputStreamReady(this); + else + mTransport->OnInputPending(); + return NS_OK; }