Bug 1369509 - Let nHttpConnectionEntry be a weak reference in HalfOpenSock. r=mcmanus

This commit is contained in:
Dragana Damjanovic 2017-06-24 06:10:58 +02:00
Родитель b9b5dda147
Коммит e72cedbf29
2 изменённых файлов: 29 добавлений и 4 удалений

Просмотреть файл

@ -612,7 +612,9 @@ nsHttpConnectionMgr::ClearConnectionHistory()
ent->mActiveConns.Length() == 0 &&
ent->mHalfOpens.Length() == 0 &&
ent->mUrgentStartQ.Length() == 0 &&
ent->PendingQLength() == 0) {
ent->PendingQLength() == 0 &&
ent->mHalfOpenFastOpenBackups.Length() == 0 &&
!ent->mDoNotDestroy) {
iter.Remove();
}
}
@ -2160,6 +2162,8 @@ nsHttpConnectionMgr::OnMsgShutdown(int32_t, ARefBase *param)
ent->mHalfOpens[i]->Abandon();
}
MOZ_ASSERT(ent->mHalfOpenFastOpenBackups.Length() == 0 &&
!ent->mDoNotDestroy);
iter.Remove();
}
@ -2496,6 +2500,8 @@ nsHttpConnectionMgr::OnMsgPruneDeadConnections(int32_t, ARefBase *)
ent->mHalfOpens.Length() == 0 &&
ent->PendingQLength() == 0 &&
ent->mUrgentStartQ.Length() == 0 &&
ent->mHalfOpenFastOpenBackups.Length() == 0 &&
!ent->mDoNotDestroy &&
(!ent->mUsingSpdy || mCT.Count() > 300)) {
LOG((" removing empty connection entry\n"));
iter.Remove();
@ -2773,6 +2779,14 @@ nsHttpConnectionMgr::OnMsgUpdateParam(int32_t inParam, ARefBase *)
// nsHttpConnectionMgr::nsConnectionEntry
nsHttpConnectionMgr::nsConnectionEntry::~nsConnectionEntry()
{
MOZ_ASSERT(!mIdleConns.Length());
MOZ_ASSERT(!mActiveConns.Length());
MOZ_ASSERT(!mHalfOpens.Length());
MOZ_ASSERT(!mUrgentStartQ.Length());
MOZ_ASSERT(!PendingQLength());
MOZ_ASSERT(!mHalfOpenFastOpenBackups.Length());
MOZ_ASSERT(!mDoNotDestroy);
MOZ_COUNT_DTOR(nsConnectionEntry);
}
@ -3956,6 +3970,7 @@ nsHalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream *out)
this, mEnt->mConnInfo->Origin(),
out == mStreamOut ? "primary" : "backup"));
mEnt->mDoNotDestroy = true;
gHttpHandler->ConnMgr()->RecvdConnect();
CancelBackupTimer();
@ -4008,8 +4023,9 @@ nsHalfOpenSocket::OnOutputStreamReady(nsIAsyncOutputStream *out)
mFastOpenInProgress = false;
mConnectionNegotiatingFastOpen = nullptr;
}
return SetupConn(out, false);
nsresult rv = SetupConn(out, false);
mEnt->mDoNotDestroy = false;
return rv;
}
bool
@ -4085,8 +4101,10 @@ nsHalfOpenSocket::StartFastOpen()
mStreamIn = nullptr;
mSocketTransport = nullptr;
mFastOpenInProgress = false;
Abandon();
return NS_ERROR_ABORT;
}
mEnt->mDoNotDestroy = true;
MOZ_ASSERT(gHttpHandler->ConnMgr()->mNumHalfOpenConns);
if (gHttpHandler->ConnMgr()->mNumHalfOpenConns) { // just in case
gHttpHandler->ConnMgr()->mNumHalfOpenConns--;
@ -4134,6 +4152,7 @@ nsHalfOpenSocket::StartFastOpen()
SetupBackupTimer();
}
}
mEnt->mDoNotDestroy = false;
return rv;
}
@ -4163,6 +4182,8 @@ nsHalfOpenSocket::SetFastOpenConnected(nsresult aError, bool aWillRetry)
RefPtr<nsHalfOpenSocket> deleteProtector(this);
mEnt->mDoNotDestroy = true;
// Delete 2 points of entry to FastOpen function so that we do not reenter.
mEnt->mHalfOpenFastOpenBackups.RemoveElement(this);
mSocketTransport->SetFastOpenCallback(nullptr);
@ -4236,6 +4257,7 @@ nsHalfOpenSocket::SetFastOpenConnected(nsresult aError, bool aWillRetry)
mFastOpenInProgress = false;
mConnectionNegotiatingFastOpen = nullptr;
mEnt->mDoNotDestroy = false;
}
void
@ -4693,6 +4715,7 @@ nsConnectionEntry::nsConnectionEntry(nsHttpConnectionInfo *ci)
, mPreferIPv4(false)
, mPreferIPv6(false)
, mUsedForConnection(false)
, mDoNotDestroy(false)
{
MOZ_COUNT_CTOR(nsConnectionEntry);
mUseFastOpen = gHttpHandler->UseFastOpen();

Просмотреть файл

@ -302,6 +302,8 @@ private:
// Try using TCP Fast Open.
bool mUseFastOpen : 1;
bool mDoNotDestroy : 1;
// Set the IP family preference flags according the connected family
void RecordIPFamilyPreference(uint16_t family);
// Resets all flags to their default values