bug 780522 - stack overflow port out of range part 2/2 r=honzab

This commit is contained in:
Patrick McManus 2012-08-09 20:38:36 -04:00
parent f71850e328
commit 757090d228
2 changed files with 52 additions and 16 deletions

View File

@ -933,8 +933,13 @@ nsHttpConnectionMgr::ProcessPendingQForEntry(nsConnectionEntry *ent)
}
rv = TryDispatchTransaction(ent, alreadyHalfOpen, trans);
if (NS_SUCCEEDED(rv)) {
LOG((" dispatching pending transaction...\n"));
if (NS_SUCCEEDED(rv) || (rv != NS_ERROR_NOT_AVAILABLE)) {
if (NS_SUCCEEDED(rv))
LOG((" dispatching pending transaction...\n"));
else
LOG((" removing pending transaction based on "
"TryDispatchTransaction returning hard error %x\n", rv));
ent->mPendingQ.RemoveElementAt(i);
NS_RELEASE(trans);
@ -1199,7 +1204,11 @@ nsHttpConnectionMgr::RestrictConnections(nsConnectionEntry *ent)
return doRestrict;
}
bool
// returns NS_OK if a connection was started
// return NS_ERROR_NOT_AVAILABLE if a new connection cannot be made due to
// ephemeral limits
// returns other NS_ERROR on hard failure conditions
nsresult
nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
nsHttpTransaction *trans)
{
@ -1220,9 +1229,9 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
ent->mConnInfo->HashKey().get()));
ent->mHalfOpens[i]->SetSpeculative(false);
// return true because we have essentially opened a new connection
// return OK because we have essentially opened a new connection
// by converting a speculative half-open to general use
return true;
return NS_OK;
}
}
@ -1230,7 +1239,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
// don't create any new connections until the result of the
// negotiation is known.
if (!(trans->Caps() & NS_HTTP_DISALLOW_SPDY) && RestrictConnections(ent))
return false;
return NS_ERROR_NOT_AVAILABLE;
// We need to make a new connection. If that is going to exceed the
// global connection limit then try and free up some room by closing
@ -1242,13 +1251,21 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
mCT.Enumerate(PurgeExcessIdleConnectionsCB, this);
if (AtActiveConnectionLimit(ent, trans->Caps()))
return false;
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = CreateTransport(ent, trans, trans->Caps(), false);
if (NS_FAILED(rv)) /* hard failure */
if (NS_FAILED(rv)) {
/* hard failure */
LOG(("nsHttpConnectionMgr::MakeNewConnection [ci = %s trans = %p] "
"CreateTransport() hard failure.\n",
ent->mConnInfo->HashKey().get(), trans));
trans->Close(rv);
if (rv == NS_ERROR_NOT_AVAILABLE)
rv = NS_ERROR_FAILURE;
return rv;
}
return true;
return NS_OK;
}
bool
@ -1374,9 +1391,11 @@ nsHttpConnectionMgr::IsUnderPressure(nsConnectionEntry *ent,
}
// returns OK if a connection is found for the transaction
// and the transaction is started.
// and the transaction is started.
// returns ERROR_NOT_AVAILABLE if no connection can be found and it
// should be queued
// should be queued until circumstances change
// returns other ERROR when transaction has a hard failure and should
// not remain in the pending queue
nsresult
nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
bool onlyReusedConnection,
@ -1484,8 +1503,18 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
}
// step 4
if (!onlyReusedConnection && MakeNewConnection(ent, trans)) {
return NS_ERROR_IN_PROGRESS;
if (!onlyReusedConnection) {
nsresult rv = MakeNewConnection(ent, trans);
if (NS_SUCCEEDED(rv)) {
// this function returns NOT_AVAILABLE for asynchronous connects
return NS_ERROR_NOT_AVAILABLE;
}
if (rv != NS_ERROR_NOT_AVAILABLE) {
// not available return codes should try next step as they are
// not hard errors. Other codes should stop now
return rv;
}
}
// step 5
@ -1678,16 +1707,23 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
else
rv = TryDispatchTransaction(ent, false, trans);
if (NS_FAILED(rv)) {
if (NS_SUCCEEDED(rv)) {
LOG((" ProcessNewTransaction Dispatch Immediately trans=%p\n", trans));
return rv;
}
if (rv == NS_ERROR_NOT_AVAILABLE) {
LOG((" adding transaction to pending queue "
"[trans=%p pending-count=%u]\n",
trans, ent->mPendingQ.Length()+1));
// put this transaction on the pending queue...
InsertTransactionSorted(ent->mPendingQ, trans);
NS_ADDREF(trans);
return NS_OK;
}
return NS_OK;
LOG((" ProcessNewTransaction Hard Error trans=%p rv=%x\n", trans, rv));
return rv;
}

View File

@ -490,7 +490,7 @@ private:
nsConnectionEntry *GetOrCreateConnectionEntry(nsHttpConnectionInfo *);
bool MakeNewConnection(nsConnectionEntry *ent,
nsresult MakeNewConnection(nsConnectionEntry *ent,
nsHttpTransaction *trans);
bool AddToShortestPipeline(nsConnectionEntry *ent,
nsHttpTransaction *trans,