Bug 1329089 - yield to other transactions while reaching the max write attempts. r=mcmanus
MozReview-Commit-ID: KHlLbvab7HZ
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -1684,17 +1684,22 @@ nsHttpConnection::OnSocketWritable()
{
LOG(("nsHttpConnection::OnSocketWritable [this=%p] host=%s\n",
this, mConnInfo->Origin()));
nsresult rv;
uint32_t transactionBytes;
bool again = true;
+ // Prevent STS thread from being blocked by single OnOutputStreamReady callback.
+ const uint32_t maxWriteAttempts = 128;
+ uint32_t writeAttempts = 0;
+
do {
+ ++writeAttempts;
rv = mSocketOutCondition = NS_OK;
transactionBytes = 0;
// The SSL handshake must be completed before the transaction->readsegments()
// processing can proceed because we need to know how to format the
// request differently for http/1, http/2, spdy, etc.. and that is
// negotiated with NPN/ALPN in the SSL handshake.
@@ -1773,16 +1778,20 @@ nsHttpConnection::OnSocketWritable()
//
mTransaction->OnTransportStatus(mSocketTransport,
NS_NET_STATUS_WAITING_FOR,
0);
rv = ResumeRecv(); // start reading
}
again = false;
+ } else if (writeAttempts >= maxWriteAttempts) {
+ LOG((" yield for other transactions\n"));
+ rv = mSocketOut->AsyncWait(this, 0, 0, nullptr); // continue writing
+ again = false;
}
// write more to the socket until error or end-of-request...
} while (again && gHttpHandler->Active());
return rv;
}
nsresult