Backed out changeset 45d37c3b7b58 (bug 1705065) for occasional crashes observed by Nightly users. CLOSED TREE

Backout requested by Dragana.
This commit is contained in:
Sebastian Hengst 2021-05-19 18:21:21 +02:00
Родитель d488467816
Коммит 2f1a015b00
8 изменённых файлов: 284 добавлений и 286 удалений

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

@ -63,18 +63,26 @@ uint32_t ConnectionEntry::UnconnectedDnsAndConnectSockets() const {
return unconnectedDnsAndConnectSockets;
}
void ConnectionEntry::InsertIntoDnsAndConnectSockets(
DnsAndConnectSocket* sock) {
mDnsAndConnectSockets.AppendElement(sock);
gHttpHandler->ConnMgr()->IncreaseNumDnsAndConnectSockets();
}
void ConnectionEntry::RemoveDnsAndConnectSocket(DnsAndConnectSocket* dnsAndSock,
bool abandon) {
if (abandon) {
dnsAndSock->Abandon();
}
bool ConnectionEntry::RemoveDnsAndConnectSocket(
DnsAndConnectSocket* dnsAndSock) {
bool isPrimary = false;
// A failure to create the transport object at all
// will result in it not being present in the DnsAndConnectSockets table.
// That's expected.
if (mDnsAndConnectSockets.RemoveElement(dnsAndSock)) {
isPrimary = true;
if (dnsAndSock->IsSpeculative()) {
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN>
unusedSpeculativeConn;
++unusedSpeculativeConn;
if (dnsAndSock->IsFromPredictor()) {
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_UNUSED>
totalPreconnectsUnused;
++totalPreconnectsUnused;
}
}
gHttpHandler->ConnMgr()->DecreaseNumDnsAndConnectSockets();
}
@ -89,20 +97,8 @@ void ConnectionEntry::RemoveDnsAndConnectSocket(DnsAndConnectSocket* dnsAndSock,
" failed to process pending queue\n"));
}
}
}
void ConnectionEntry::CloseAllDnsAndConnectSockets() {
for (const auto& dnsAndSock : mDnsAndConnectSockets) {
dnsAndSock->Abandon();
gHttpHandler->ConnMgr()->DecreaseNumDnsAndConnectSockets();
}
mDnsAndConnectSockets.Clear();
nsresult rv = gHttpHandler->ConnMgr()->ProcessPendingQ(mConnInfo);
if (NS_FAILED(rv)) {
LOG(
("ConnectionEntry::CloseAllDnsAndConnectSockets\n"
" failed to process pending queue\n"));
}
return isPrimary;
}
void ConnectionEntry::DisallowHttp2() {
@ -523,16 +519,25 @@ void ConnectionEntry::MakeAllDontReuseExcept(HttpConnectionBase* conn) {
// Cancel any other pending connections - their associated transactions
// are in the pending queue and will be dispatched onto this new connection
CloseAllDnsAndConnectSockets();
for (int32_t index = DnsAndConnectSocketsLength() - 1; index >= 0; --index) {
RefPtr<DnsAndConnectSocket> dnsAndSock = mDnsAndConnectSockets[index];
LOG(
("ConnectionEntry::MakeAllDontReuseExcept forcing DnsAndConnectSocket "
"abandon %p\n",
dnsAndSock.get()));
mDnsAndConnectSockets[index]->Abandon();
}
}
bool ConnectionEntry::FindConnToClaim(
PendingTransactionInfo* pendingTransInfo) {
nsHttpTransaction* trans = pendingTransInfo->Transaction();
for (const auto& dnsAndSock : mDnsAndConnectSockets) {
if (dnsAndSock->AcceptsTransaction(trans) && dnsAndSock->Claim()) {
pendingTransInfo->RememberDnsAndConnectSocket(dnsAndSock);
uint32_t dnsAndSockLength = DnsAndConnectSocketsLength();
for (uint32_t i = 0; i < dnsAndSockLength; i++) {
auto* dnsAndSock = mDnsAndConnectSockets[i];
if (dnsAndSock->AcceptsTransaction(trans) &&
pendingTransInfo->TryClaimingDnsAndConnectSocket(dnsAndSock)) {
// We've found a speculative connection or a connection that
// is free to be used in the DnsAndConnectSockets list.
// A free to be used connection is a connection that was
@ -717,7 +722,10 @@ uint32_t ConnectionEntry::TimeoutTick() {
TimeStamp currentTime = TimeStamp::Now();
double maxConnectTime_ms = gHttpHandler->ConnectTimeout();
for (const auto& dnsAndSock : Reversed(mDnsAndConnectSockets)) {
for (uint32_t index = mDnsAndConnectSockets.Length(); index > 0;) {
index--;
DnsAndConnectSocket* dnsAndSock = mDnsAndConnectSockets[index];
double delta = dnsAndSock->Duration(currentTime);
// If the socket has timed out, close it so the waiting
// transaction will get the proper signal.
@ -732,7 +740,7 @@ uint32_t ConnectionEntry::TimeoutTick() {
if (delta > maxConnectTime_ms + 5000) {
LOG(("Abandon DnsAndConnectSocket to %s after %.2fms.\n",
mConnInfo->HashKey().get(), delta));
RemoveDnsAndConnectSocket(dnsAndSock, true);
dnsAndSock->Abandon();
}
}
}
@ -762,6 +770,22 @@ void ConnectionEntry::MoveConnection(HttpConnectionBase* proxyConn,
}
}
void ConnectionEntry::InsertIntoDnsAndConnectSockets(
DnsAndConnectSocket* sock) {
mDnsAndConnectSockets.AppendElement(sock);
gHttpHandler->ConnMgr()->IncreaseNumDnsAndConnectSockets();
}
void ConnectionEntry::CloseAllDnsAndConnectSockets() {
for (int32_t i = int32_t(DnsAndConnectSocketsLength()) - 1; i >= 0; i--) {
mDnsAndConnectSockets[i]->Abandon();
}
}
bool ConnectionEntry::IsInDnsAndConnectSockets(DnsAndConnectSocket* sock) {
return mDnsAndConnectSockets.Contains(sock);
}
HttpRetParams ConnectionEntry::GetConnectionData() {
HttpRetParams data;
data.host = mConnInfo->Origin();
@ -861,11 +885,7 @@ bool ConnectionEntry::RemoveTransFromPendingQ(nsHttpTransaction* aTrans) {
}
// Abandon all DnsAndConnectSockets belonging to the given transaction.
nsWeakPtr tmp = pendingTransInfo->ForgetDnsAndConnectSocketAndActiveConn();
RefPtr<DnsAndConnectSocket> dnsAndSock = do_QueryReferent(tmp);
if (dnsAndSock) {
RemoveDnsAndConnectSocket(dnsAndSock, true);
}
pendingTransInfo->AbandonDnsAndConnectSocketAndForgetActiveConn();
return true;
}
@ -891,81 +911,5 @@ void ConnectionEntry::MaybeUpdateEchConfig(nsHttpConnectionInfo* aConnInfo) {
CloseIdleConnections();
}
nsresult ConnectionEntry::CreateDnsAndConnectSocket(nsAHttpTransaction* trans, uint32_t caps,
bool speculative, bool isFromPredictor, bool urgentStart, bool allow1918,
PendingTransactionInfo* pendingTransInfo) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
MOZ_ASSERT((speculative && !pendingTransInfo) ||
(!speculative && pendingTransInfo));
RefPtr<DnsAndConnectSocket> sock = new DnsAndConnectSocket(
mConnInfo, trans, caps, speculative, isFromPredictor, urgentStart);
if (speculative) {
sock->SetAllow1918(allow1918);
}
nsresult rv = sock->Init(this);
NS_ENSURE_SUCCESS(rv, rv);
InsertIntoDnsAndConnectSockets(sock);
if (pendingTransInfo && sock->Claim()) {
pendingTransInfo->RememberDnsAndConnectSocket(sock);
}
return NS_OK;
}
bool ConnectionEntry::MaybeProcessCoalescingKeys(nsIDNSAddrRecord* dnsRecord) {
if (!mConnInfo || !AllowHttp2() || !mCoalescingKeys.IsEmpty() || !dnsRecord) {
return false;
}
nsTArray<NetAddr> addressSet;
nsresult rv = dnsRecord->GetAddresses(addressSet);
if (NS_FAILED(rv) || addressSet.IsEmpty()) {
return false;
}
for (uint32_t i = 0; i < addressSet.Length(); ++i) {
if ((addressSet[i].raw.family == AF_INET &&
addressSet[i].inet.ip == 0) ||
(addressSet[i].raw.family == AF_INET6 &&
addressSet[i].inet6.ip.u64[0] == 0 &&
addressSet[i].inet6.ip.u64[1] == 0)) {
// Bug 1680249 - Don't create the coalescing key if the ip address is
// `0.0.0.0` or `::`.
LOG((
"ConnectionEntry::MaybeProcessCoalescingKeys skip creating "
"Coalescing Key for host [%s]",
mConnInfo->Origin()));
continue;
}
nsCString* newKey = mCoalescingKeys.AppendElement(nsCString());
newKey->SetLength(kIPv6CStrBufSize + 26);
addressSet[i].ToStringBuffer(newKey->BeginWriting(), kIPv6CStrBufSize);
newKey->SetLength(strlen(newKey->BeginReading()));
if (mConnInfo->GetAnonymous()) {
newKey->AppendLiteral("~A:");
} else {
newKey->AppendLiteral("~.:");
}
newKey->AppendInt(mConnInfo->OriginPort());
newKey->AppendLiteral("/[");
nsAutoCString suffix;
mConnInfo->GetOriginAttributes().CreateSuffix(suffix);
newKey->Append(suffix);
newKey->AppendLiteral("]viaDNS");
LOG((
"ConnectionEntry::MaybeProcessCoalescingKeys "
"Established New Coalescing Key # %d for host "
"%s [%s]",
i, mConnInfo->Origin(), newKey->get()));
}
return true;
}
} // namespace net
} // namespace mozilla

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

@ -84,8 +84,8 @@ class ConnectionEntry {
}
void InsertIntoDnsAndConnectSockets(DnsAndConnectSocket* sock);
void RemoveDnsAndConnectSocket(DnsAndConnectSocket* dnsAndSock, bool abandon);
void CloseAllDnsAndConnectSockets();
bool IsInDnsAndConnectSockets(DnsAndConnectSocket* sock);
HttpRetParams GetConnectionData();
void LogConnections();
@ -101,13 +101,6 @@ class ConnectionEntry {
// Remove a particular DnsAndConnectSocket from the mDnsAndConnectSocket array
bool RemoveDnsAndConnectSocket(DnsAndConnectSocket*);
nsresult CreateDnsAndConnectSocket(nsAHttpTransaction* trans, uint32_t caps,
bool speculative, bool isFromPredictor,
bool urgentStart, bool allow1918,
PendingTransactionInfo* pendingTransInfo);
bool MaybeProcessCoalescingKeys(nsIDNSAddrRecord* dnsRecord);
// Spdy sometimes resolves the address in the socket manager in order
// to re-coalesce sharded HTTP hosts. The dotted decimal address is
// combined with the Anonymous flag and OA from the connection information
@ -197,7 +190,7 @@ class ConnectionEntry {
nsTArray<RefPtr<nsHttpConnection>> mIdleConns; // idle persistent connections
nsTArray<RefPtr<HttpConnectionBase>> mActiveConns; // active connections
nsTArray<RefPtr<DnsAndConnectSocket>>
nsTArray<DnsAndConnectSocket*>
mDnsAndConnectSockets; // dns resolution and half open connections
PendingTransactionQueue mPendingQ;

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

@ -41,7 +41,7 @@ NS_INTERFACE_MAP_BEGIN(DnsAndConnectSocket)
NS_INTERFACE_MAP_ENTRY_CONCRETE(DnsAndConnectSocket)
NS_INTERFACE_MAP_END
DnsAndConnectSocket::DnsAndConnectSocket(nsHttpConnectionInfo* ci,
DnsAndConnectSocket::DnsAndConnectSocket(ConnectionEntry* ent,
nsAHttpTransaction* trans,
uint32_t caps, bool speculative,
bool isFromPredictor, bool urgentStart)
@ -51,13 +51,13 @@ DnsAndConnectSocket::DnsAndConnectSocket(nsHttpConnectionInfo* ci,
mSpeculative(speculative),
mUrgentStart(urgentStart),
mIsFromPredictor(isFromPredictor),
mConnInfo(ci),
mEnt(ent),
mBackupTransport(true) {
MOZ_ASSERT(ci && trans, "constructor with null arguments");
MOZ_ASSERT(ent && trans, "constructor with null arguments");
LOG(("Creating DnsAndConnectSocket [this=%p trans=%p ent=%s key=%s]\n", this,
trans, mConnInfo->Origin(), mConnInfo->HashKey().get()));
trans, ent->mConnInfo->Origin(), ent->mConnInfo->HashKey().get()));
mIsHttp3 = mConnInfo->IsHttp3();
mIsHttp3 = mEnt->mConnInfo->IsHttp3();
if (speculative) {
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN>
totalSpeculativeConn;
@ -70,7 +70,7 @@ DnsAndConnectSocket::DnsAndConnectSocket(nsHttpConnectionInfo* ci,
}
}
MOZ_ASSERT(mConnInfo);
MOZ_ASSERT(mEnt);
}
DnsAndConnectSocket::~DnsAndConnectSocket() {
@ -81,46 +81,45 @@ DnsAndConnectSocket::~DnsAndConnectSocket() {
MOZ_ASSERT(!mPrimaryTransport.mWaitingForConnect);
MOZ_ASSERT(!mBackupTransport.mWaitingForConnect);
// Check in case something goes wrong that we decrease
// the nsHttpConnectionMgr active connection number.
// the nsHttpConnectionMgr active connecttion number.
mPrimaryTransport.MaybeSetConnectingDone();
mBackupTransport.MaybeSetConnectingDone();
if (mSpeculative) {
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN>
unusedSpeculativeConn;
++unusedSpeculativeConn;
if (mIsFromPredictor) {
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_UNUSED>
totalPreconnectsUnused;
++totalPreconnectsUnused;
}
if (mEnt) {
bool inqueue = mEnt->RemoveDnsAndConnectSocket(this);
LOG((
"Destroying DnsAndConnectSocket was in the HalfOpenList=%d [this=%p]\n",
inqueue, this));
}
}
nsresult DnsAndConnectSocket::Init(ConnectionEntry* ent) {
nsresult DnsAndConnectSocket::Init() {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
MOZ_ASSERT(mEnt);
MOZ_ASSERT(mState == DnsAndSocketState::INIT);
if (mConnInfo->GetRoutedHost().IsEmpty()) {
mPrimaryTransport.mHost = mConnInfo->GetOrigin();
mBackupTransport.mHost = mConnInfo->GetOrigin();
if (mEnt->mConnInfo->GetRoutedHost().IsEmpty()) {
mPrimaryTransport.mHost = mEnt->mConnInfo->GetOrigin();
mBackupTransport.mHost = mEnt->mConnInfo->GetOrigin();
} else {
mPrimaryTransport.mHost = mConnInfo->GetRoutedHost();
mBackupTransport.mHost = mConnInfo->GetRoutedHost();
mPrimaryTransport.mHost = mEnt->mConnInfo->GetRoutedHost();
mBackupTransport.mHost = mEnt->mConnInfo->GetRoutedHost();
}
CheckProxyConfig();
if (!mSkipDnsResolution) {
nsresult rv = SetupDnsFlags(ent);
nsresult rv = SetupDnsFlags();
NS_ENSURE_SUCCESS(rv, rv);
}
return SetupEvent(SetupEvents::INIT_EVENT);
}
void DnsAndConnectSocket::CheckProxyConfig() {
if (nsCOMPtr<nsProxyInfo> proxyInfo = mConnInfo->ProxyInfo()) {
const nsHttpConnectionInfo* ci = mEnt->mConnInfo;
if (ci->ProxyInfo()) {
nsCOMPtr<nsProxyInfo> proxyInfo = ci->ProxyInfo();
nsAutoCString proxyType(proxyInfo->Type());
bool proxyTransparent = false;
@ -152,7 +151,7 @@ void DnsAndConnectSocket::CheckProxyConfig() {
}
}
nsresult DnsAndConnectSocket::SetupDnsFlags(ConnectionEntry* ent) {
nsresult DnsAndConnectSocket::SetupDnsFlags() {
LOG(("DnsAndConnectSocket::SetupDnsFlags [this=%p] ", this));
uint32_t dnsFlags = 0;
@ -164,10 +163,10 @@ nsresult DnsAndConnectSocket::SetupDnsFlags(ConnectionEntry* ent) {
dnsFlags |= nsIDNSService::RESOLVE_DISABLE_IPV4;
} else if (mCaps & NS_HTTP_DISABLE_IPV6) {
dnsFlags |= nsIDNSService::RESOLVE_DISABLE_IPV6;
} else if (ent->PreferenceKnown()) {
if (ent->mPreferIPv6) {
} else if (mEnt->PreferenceKnown()) {
if (mEnt->mPreferIPv6) {
dnsFlags |= nsIDNSService::RESOLVE_DISABLE_IPV4;
} else if (ent->mPreferIPv4) {
} else if (mEnt->mPreferIPv4) {
dnsFlags |= nsIDNSService::RESOLVE_DISABLE_IPV6;
}
mPrimaryTransport.mRetryWithDifferentIPFamily = true;
@ -181,7 +180,7 @@ nsresult DnsAndConnectSocket::SetupDnsFlags(ConnectionEntry* ent) {
disableIpv6ForBackup = true;
}
if (ent->mConnInfo->HasIPHintAddress()) {
if (mEnt->mConnInfo->HasIPHintAddress()) {
nsresult rv;
nsCOMPtr<nsIDNSService> dns =
do_GetService("@mozilla.org/network/dns-service;1", &rv);
@ -195,7 +194,7 @@ nsresult DnsAndConnectSocket::SetupDnsFlags(ConnectionEntry* ent) {
nsCOMPtr<nsIDNSRecord> record;
rv = dns->ResolveNative(
mPrimaryTransport.mHost, nsIDNSService::RESOLVE_OFFLINE,
mConnInfo->GetOriginAttributes(), getter_AddRefs(record));
mEnt->mConnInfo->GetOriginAttributes(), getter_AddRefs(record));
if (NS_FAILED(rv) || !record) {
LOG(("Setting Socket to use IP hint address"));
dnsFlags |= nsIDNSService::RESOLVE_IP_HINT;
@ -231,29 +230,27 @@ nsresult DnsAndConnectSocket::SetupDnsFlags(ConnectionEntry* ent) {
nsresult DnsAndConnectSocket::SetupEvent(SetupEvents event) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
LOG(("DnsAndConnectSocket::SetupEvent state=%d event=%d this=%p", mState,
event, this));
nsresult rv = NS_OK;
LOG(("DnsAndConnectSocket::SetupEvent state=%d event=%d", mState, event));
switch (event) {
case SetupEvents::INIT_EVENT:
case SetupEvents::INIT_EVENT: {
MOZ_ASSERT(mState == DnsAndSocketState::INIT);
rv = mPrimaryTransport.Init(this);
nsresult rv = mPrimaryTransport.Init(this);
if (NS_FAILED(rv)) {
mState = DnsAndSocketState::DONE;
} else if (mPrimaryTransport.FirstResolving()) {
return rv;
}
if (mPrimaryTransport.FirstResolving()) {
mState = DnsAndSocketState::RESOLVING;
} else if (!mIsHttp3 && mPrimaryTransport.ConnectingOrRetry()) {
mState = DnsAndSocketState::CONNECTING;
SetupBackupTimer();
} else {
MOZ_ASSERT(false);
mState = DnsAndSocketState::DONE;
Abandon();
rv = NS_ERROR_UNEXPECTED;
return NS_ERROR_UNEXPECTED;
}
break;
} break;
case SetupEvents::RESOLVED_PRIMARY_EVENT:
// This event may be posted multiple times if a DNS lookup is
// This eventt may be posted multiple times if a DNS lookup is
// retriggered, e.g with different parameter.
if (!mIsHttp3 && (mState == DnsAndSocketState::RESOLVING)) {
mState = DnsAndSocketState::CONNECTING;
@ -287,19 +284,11 @@ nsresult DnsAndConnectSocket::SetupEvent(SetupEvents event) {
}
LOG(("DnsAndConnectSocket::SetupEvent state=%d", mState));
if (mState == DnsAndSocketState::DONE) {
RefPtr<DnsAndConnectSocket> self(this);
RefPtr<ConnectionEntry> ent =
gHttpHandler->ConnMgr()->FindConnectionEntry(mConnInfo);
if (ent) {
ent->RemoveDnsAndConnectSocket(this, false);
}
return rv;
}
return NS_OK;
}
void DnsAndConnectSocket::SetupBackupTimer() {
MOZ_ASSERT(mEnt);
uint16_t timeout = gHttpHandler->GetIdleSynTimeout();
MOZ_ASSERT(!mSynTimer, "timer already initd");
@ -338,12 +327,14 @@ void DnsAndConnectSocket::CancelBackupTimer() {
void DnsAndConnectSocket::Abandon() {
LOG(("DnsAndConnectSocket::Abandon [this=%p ent=%s] %p %p %p %p", this,
mConnInfo->Origin(), mPrimaryTransport.mSocketTransport.get(),
mEnt->mConnInfo->Origin(), mPrimaryTransport.mSocketTransport.get(),
mBackupTransport.mSocketTransport.get(),
mPrimaryTransport.mStreamOut.get(), mBackupTransport.mStreamOut.get()));
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
RefPtr<DnsAndConnectSocket> deleteProtector(this);
// Tell socket (and backup socket) to forget the half open socket.
mPrimaryTransport.Abandon();
mBackupTransport.Abandon();
@ -352,6 +343,13 @@ void DnsAndConnectSocket::Abandon() {
CancelBackupTimer();
mState = DnsAndSocketState::DONE;
// Remove the half open from the connection entry.
if (mEnt) {
mEnt->mDoNotDestroy = false;
mEnt->RemoveDnsAndConnectSocket(this);
}
mEnt = nullptr;
}
double DnsAndConnectSocket::Duration(TimeStamp epoch) {
@ -370,6 +368,7 @@ DnsAndConnectSocket::Notify(nsITimer* timer) {
MOZ_ASSERT(!mBackupTransport.mDNSRequest);
MOZ_ASSERT(!mBackupTransport.mSocketTransport);
MOZ_ASSERT(mSynTimer);
MOZ_ASSERT(mEnt);
DebugOnly<nsresult> rv = SetupEvent(BACKUP_TIMER_FIRED_EVENT);
MOZ_ASSERT(NS_SUCCEEDED(rv));
@ -415,7 +414,7 @@ DnsAndConnectSocket::OnLookupComplete(nsICancelable* request, nsIDNSRecord* rec,
// remember if it was primary because TransportSetups will delete the ref to
// the DNS request and check cannot be performed later.
bool isPrimary = IsPrimary(request);
if (isPrimary) {
if (IsPrimary(request)) {
rv = mPrimaryTransport.OnLookupComplete(this, rec, status);
if ((!mIsHttp3 && mPrimaryTransport.ConnectingOrRetry()) ||
(mIsHttp3 && mPrimaryTransport.Resolved())) {
@ -426,21 +425,7 @@ DnsAndConnectSocket::OnLookupComplete(nsICancelable* request, nsIDNSRecord* rec,
}
if (NS_FAILED(rv) || mIsHttp3) {
// Before calling SetupConn we need to hold reference to this, i.e. a
// delete protector, because the corresponding ConnectionEntry may be
// abandoned and that will abandon this DnsAndConnectSocket.
SetupConn(isPrimary, rv);
// During a connection dispatch that will happen in SetupConn,
// a ConnectionEntry may be abandon and that will abandon this
// DnsAndConnectSocket. In that case mState will already be
// DnsAndSocketState::DONE and we do not need to set it again.
if (mState != DnsAndSocketState::DONE) {
if (isPrimary) {
SetupEvent(SetupEvents::PRIMARY_DONE_EVENT);
} else {
SetupEvent(SetupEvents::BACKUP_DONE_EVENT);
}
}
}
return NS_OK;
}
@ -452,11 +437,12 @@ DnsAndConnectSocket::OnOutputStreamReady(nsIAsyncOutputStream* out) {
MOZ_ASSERT(mPrimaryTransport.mSocketTransport ||
mBackupTransport.mSocketTransport);
MOZ_ASSERT(IsPrimary(out) || IsBackup(out), "stream mismatch");
MOZ_ASSERT(mEnt);
RefPtr<DnsAndConnectSocket> deleteProtector(this);
LOG(("DnsAndConnectSocket::OnOutputStreamReady [this=%p ent=%s %s]\n", this,
mConnInfo->Origin(), IsPrimary(out) ? "primary" : "backup"));
mEnt->mConnInfo->Origin(), IsPrimary(out) ? "primary" : "backup"));
// Remember if it was primary or backup reuest.
bool isPrimary = IsPrimary(out);
@ -492,43 +478,27 @@ DnsAndConnectSocket::OnOutputStreamReady(nsIAsyncOutputStream* out) {
return NS_ERROR_UNEXPECTED;
}
// Before calling SetupConn we need to hold a reference to this, i.e. a
// delete protector, because the corresponding ConnectionEntry may be
// abandoned and that will abandon this DnsAndConnectSocket.
mEnt->mDoNotDestroy = true;
rv = SetupConn(isPrimary, rv);
if (mState != DnsAndSocketState::DONE) {
// During a connection dispatch that will happen in SetupConn,
// a ConnectionEntry may be abandon and that will abandon this
// DnsAndConnectSocket. In that case mState will already be
// DnsAndSocketState::DONE and we do not need to set it again.
if (isPrimary) {
SetupEvent(SetupEvents::PRIMARY_DONE_EVENT);
} else {
SetupEvent(SetupEvents::BACKUP_DONE_EVENT);
}
if (mEnt) {
mEnt->mDoNotDestroy = false;
}
return rv;
}
nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
// assign the new socket to the http connection
RefPtr<ConnectionEntry> ent =
gHttpHandler->ConnMgr()->FindConnectionEntry(mConnInfo);
MOZ_DIAGNOSTIC_ASSERT(ent);
if (!ent) {
Abandon();
return NS_OK;
}
RefPtr<HttpConnectionBase> conn;
nsresult rv = NS_OK;
if (isPrimary) {
rv = mPrimaryTransport.SetupConn(mTransaction, ent, status, mCaps,
SetupEvent(SetupEvents::PRIMARY_DONE_EVENT);
rv = mPrimaryTransport.SetupConn(mTransaction, mEnt, status, mCaps,
getter_AddRefs(conn));
} else {
rv = mBackupTransport.SetupConn(mTransaction, ent, status, mCaps,
SetupEvent(SetupEvents::BACKUP_DONE_EVENT);
rv = mBackupTransport.SetupConn(mTransaction, mEnt, status, mCaps,
getter_AddRefs(conn));
}
@ -544,12 +514,12 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
if (nsHttpTransaction* trans = mTransaction->QueryHttpTransaction()) {
if (mIsHttp3) {
trans->DisableHttp3();
gHttpHandler->ExcludeHttp3(mConnInfo);
gHttpHandler->ExcludeHttp3(mEnt->mConnInfo);
}
// The transaction's connection info is changed after DisableHttp3(), so
// this is the only point we can remove this transaction from its conn
// entry.
ent->RemoveTransFromPendingQ(trans);
mEnt->RemoveTransFromPendingQ(trans);
}
mTransaction->Close(rv);
@ -562,11 +532,11 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
// if this is still in the pending list, remove it and dispatch it
RefPtr<PendingTransactionInfo> pendingTransInfo =
gHttpHandler->ConnMgr()->FindTransactionHelper(true, ent, mTransaction);
gHttpHandler->ConnMgr()->FindTransactionHelper(true, mEnt, mTransaction);
if (pendingTransInfo) {
MOZ_ASSERT(!mSpeculative, "Speculative Half Open found mTransaction");
ent->InsertIntoActiveConns(conn);
mEnt->InsertIntoActiveConns(conn);
if (mIsHttp3) {
// Each connection must have a ConnectionHandle wrapper.
// In case of Http < 2 the a ConnectionHandle is created for each
@ -585,7 +555,7 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
pendingTransInfo->Transaction()->SetConnection(handle);
}
rv = gHttpHandler->ConnMgr()->DispatchTransaction(
ent, pendingTransInfo->Transaction(), conn);
mEnt, pendingTransInfo->Transaction(), conn);
} else {
// this transaction was dispatched off the pending q before all the
// sockets established themselves.
@ -606,8 +576,8 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
// Http3 cannot be dispatched using OnMsgReclaimConnection (see below),
// therefore we need to use a Nulltransaction.
if (!connTCP ||
(ent->mConnInfo->FirstHopSSL() && !ent->UrgentStartQueueLength() &&
!ent->PendingQueueLength() && !ent->mConnInfo->UsingConnect())) {
(mEnt->mConnInfo->FirstHopSSL() && !mEnt->UrgentStartQueueLength() &&
!mEnt->PendingQueueLength() && !mEnt->mConnInfo->UsingConnect())) {
LOG(
("DnsAndConnectSocket::SetupConn null transaction will "
"be used to finish SSL handshake on conn %p\n",
@ -619,11 +589,11 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
mDispatchedMTransaction = true;
trans = mTransaction;
} else {
trans = new NullHttpTransaction(mConnInfo, callbacks, mCaps);
trans = new NullHttpTransaction(mEnt->mConnInfo, callbacks, mCaps);
}
ent->InsertIntoActiveConns(conn);
rv = gHttpHandler->ConnMgr()->DispatchAbstractTransaction(ent, trans,
mEnt->InsertIntoActiveConns(conn);
rv = gHttpHandler->ConnMgr()->DispatchAbstractTransaction(mEnt, trans,
mCaps, conn, 0);
} else {
// otherwise just put this in the persistent connection pool
@ -640,22 +610,24 @@ nsresult DnsAndConnectSocket::SetupConn(bool isPrimary, nsresult status) {
// idle queue.
// If the connection is in the idle queue but it is using ssl, make
// a nulltransaction for it to finish ssl handshake!
if (ent->mConnInfo->FirstHopSSL() &&
!ent->mConnInfo->UsingConnect()) {
// !!! It can be that mEnt is null after OnMsgReclaimConnection.!!!
if (mEnt && mEnt->mConnInfo->FirstHopSSL() &&
!mEnt->mConnInfo->UsingConnect()) {
RefPtr<nsHttpConnection> connTCP = do_QueryObject(conn);
// If RemoveIdleConnection succeeds that means that conn is in the
// idle queue.
if (connTCP && NS_SUCCEEDED(ent->RemoveIdleConnection(connTCP))) {
if (connTCP && NS_SUCCEEDED(mEnt->RemoveIdleConnection(connTCP))) {
RefPtr<nsAHttpTransaction> trans;
if (mTransaction->IsNullTransaction() && !mDispatchedMTransaction) {
mDispatchedMTransaction = true;
trans = mTransaction;
} else {
trans = new NullHttpTransaction(ent->mConnInfo, callbacks, mCaps);
trans = new NullHttpTransaction(mEnt->mConnInfo, callbacks, mCaps);
}
ent->InsertIntoActiveConns(conn);
mEnt->InsertIntoActiveConns(conn);
rv = gHttpHandler->ConnMgr()->DispatchAbstractTransaction(
ent, trans, mCaps, conn, 0);
mEnt, trans, mCaps, conn, 0);
}
}
}
@ -677,6 +649,7 @@ DnsAndConnectSocket::OnTransportStatus(nsITransport* trans, nsresult status,
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
MOZ_ASSERT(IsPrimary(trans) || IsBackup(trans));
MOZ_ASSERT(mEnt);
if (mTransaction) {
if (IsPrimary(trans) ||
(IsBackup(trans) && (status == NS_NET_STATUS_CONNECTED_TO) &&
@ -712,18 +685,55 @@ DnsAndConnectSocket::OnTransportStatus(nsITransport* trans, nsresult status,
// for this entry before then make the hash key if our dns lookup
// just completed. We can't do coalescing if using a proxy because the
// ip addresses are not available to the client.
nsCOMPtr<nsIDNSAddrRecord> dnsRecord(
do_GetInterface(mPrimaryTransport.mSocketTransport));
if (status == NS_NET_STATUS_CONNECTING_TO && gHttpHandler->IsSpdyEnabled() &&
gHttpHandler->CoalesceSpdy() && mConnInfo && mConnInfo->EndToEndSSL() &&
!mConnInfo->UsingProxy() && dnsRecord) {
RefPtr<ConnectionEntry> ent = gHttpHandler->ConnMgr()->FindConnectionEntry(mConnInfo);
MOZ_DIAGNOSTIC_ASSERT(ent);
if (ent) {
if (ent->MaybeProcessCoalescingKeys(dnsRecord)) {
gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(ent);
if (status == NS_NET_STATUS_CONNECTING_TO && gHttpHandler->IsSpdyEnabled() &&
gHttpHandler->CoalesceSpdy() && mEnt && mEnt->mConnInfo &&
mEnt->mConnInfo->EndToEndSSL() && mEnt->AllowHttp2() &&
!mEnt->mConnInfo->UsingProxy() && mEnt->mCoalescingKeys.IsEmpty()) {
nsCOMPtr<nsIDNSAddrRecord> dnsRecord(
do_GetInterface(mPrimaryTransport.mSocketTransport));
nsTArray<NetAddr> addressSet;
nsresult rv = NS_ERROR_NOT_AVAILABLE;
if (dnsRecord) {
rv = dnsRecord->GetAddresses(addressSet);
}
if (NS_SUCCEEDED(rv) && !addressSet.IsEmpty()) {
for (uint32_t i = 0; i < addressSet.Length(); ++i) {
if ((addressSet[i].raw.family == AF_INET &&
addressSet[i].inet.ip == 0) ||
(addressSet[i].raw.family == AF_INET6 &&
addressSet[i].inet6.ip.u64[0] == 0 &&
addressSet[i].inet6.ip.u64[1] == 0)) {
// Bug 1680249 - Don't create the coalescing key if the ip address is
// `0.0.0.0` or `::`.
LOG((
"DnsAndConnectSocket: skip creating Coalescing Key for host [%s]",
mEnt->mConnInfo->Origin()));
continue;
}
nsCString* newKey = mEnt->mCoalescingKeys.AppendElement(nsCString());
newKey->SetLength(kIPv6CStrBufSize + 26);
addressSet[i].ToStringBuffer(newKey->BeginWriting(), kIPv6CStrBufSize);
newKey->SetLength(strlen(newKey->BeginReading()));
if (mEnt->mConnInfo->GetAnonymous()) {
newKey->AppendLiteral("~A:");
} else {
newKey->AppendLiteral("~.:");
}
newKey->AppendInt(mEnt->mConnInfo->OriginPort());
newKey->AppendLiteral("/[");
nsAutoCString suffix;
mEnt->mConnInfo->GetOriginAttributes().CreateSuffix(suffix);
newKey->Append(suffix);
newKey->AppendLiteral("]viaDNS");
LOG((
"DnsAndConnectSocket::OnTransportStatus "
"STATUS_CONNECTING_TO Established New Coalescing Key # %d for host "
"%s [%s]",
i, mEnt->mConnInfo->Origin(), newKey->get()));
}
gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(mEnt);
}
}
@ -797,7 +807,7 @@ bool DnsAndConnectSocket::Claim() {
// Http3 has its own syn-retransmission, therefore it does not need a
// backup connection.
if (mPrimaryTransport.ConnectingOrRetry() &&
if (mPrimaryTransport.ConnectingOrRetry() && mEnt &&
!mBackupTransport.mSocketTransport && !mSynTimer && !mIsHttp3) {
SetupBackupTimer();
}
@ -1015,7 +1025,6 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupConn(
NS_SUCCEEDED(mSocketTransport->GetPeerAddr(&peeraddr))) {
ent->RecordIPFamilyPreference(peeraddr.raw.family);
}
conn.forget(connection);
mSocketTransport = nullptr;
mStreamOut = nullptr;
@ -1028,9 +1037,10 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupStreams(
DnsAndConnectSocket* dnsAndSock) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
MOZ_ASSERT(dnsAndSock->mEnt);
nsresult rv;
nsTArray<nsCString> socketTypes;
const nsHttpConnectionInfo* ci = dnsAndSock->mConnInfo;
const nsHttpConnectionInfo* ci = dnsAndSock->mEnt->mConnInfo;
if (dnsAndSock->mIsHttp3) {
socketTypes.AppendElement("quic"_ns);
} else {
@ -1128,7 +1138,7 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupStreams(
// record is in cache before setting USE_IP_HINT_ADDRESS.
nsCOMPtr<nsIDNSRecord> record;
rv = dns->ResolveNative(mHost, nsIDNSService::RESOLVE_OFFLINE,
dnsAndSock->mConnInfo->GetOriginAttributes(),
dnsAndSock->mEnt->mConnInfo->GetOriginAttributes(),
getter_AddRefs(record));
if (NS_FAILED(rv) || !record) {
LOG(("Setting Socket to use IP hint address"));
@ -1136,7 +1146,21 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupStreams(
}
}
if (mRetryWithDifferentIPFamily) {
if (dnsAndSock->mCaps & NS_HTTP_DISABLE_IPV4) {
tmpFlags |= nsISocketTransport::DISABLE_IPV4;
} else if (dnsAndSock->mCaps & NS_HTTP_DISABLE_IPV6) {
tmpFlags |= nsISocketTransport::DISABLE_IPV6;
} else if (dnsAndSock->mEnt->PreferenceKnown()) {
if (dnsAndSock->mEnt->mPreferIPv6) {
tmpFlags |= nsISocketTransport::DISABLE_IPV4;
} else if (dnsAndSock->mEnt->mPreferIPv4) {
tmpFlags |= nsISocketTransport::DISABLE_IPV6;
}
// In case the host is no longer accessible via the preferred IP family,
// try the opposite one and potentially restate the preference.
tmpFlags |= nsISocketTransport::RETRY_WITH_DIFFERENT_IP_FAMILY;
// From the same reason, let the backup socket fail faster to try the other
// family.
uint16_t fallbackTimeout =
@ -1145,16 +1169,27 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupStreams(
socketTransport->SetTimeout(nsISocketTransport::TIMEOUT_CONNECT,
fallbackTimeout);
}
} else if (mIsBackup && gHttpHandler->FastFallbackToIPv4()) {
// For backup connections, we disable IPv6. That's because some users have
// broken IPv6 connectivity (leading to very long timeouts), and disabling
// IPv6 on the backup connection gives them a much better user experience
// with dual-stack hosts, though they still pay the 250ms delay for each new
// connection. This strategy is also known as "happy eyeballs".
tmpFlags |= nsISocketTransport::DISABLE_IPV6;
}
if (!dnsAndSock->Allow1918()) {
tmpFlags |= nsISocketTransport::DISABLE_RFC1918;
}
MOZ_ASSERT(!(tmpFlags & nsISocketTransport::DISABLE_IPV4) ||
!(tmpFlags & nsISocketTransport::DISABLE_IPV6),
"Both types should not be disabled at the same time.");
socketTransport->SetConnectionFlags(tmpFlags);
socketTransport->SetTlsFlags(ci->GetTlsFlags());
const OriginAttributes& originAttributes = dnsAndSock->mConnInfo->GetOriginAttributes();
const OriginAttributes& originAttributes =
dnsAndSock->mEnt->mConnInfo->GetOriginAttributes();
if (originAttributes != OriginAttributes()) {
socketTransport->SetOriginAttributes(originAttributes);
}
@ -1172,13 +1207,9 @@ nsresult DnsAndConnectSocket::TransportSetup::SetupStreams(
NS_ENSURE_SUCCESS(rv, rv);
}
RefPtr<ConnectionEntry> ent = gHttpHandler->ConnMgr()->FindConnectionEntry(ci);
MOZ_DIAGNOSTIC_ASSERT(ent);
if (ent) {
Telemetry::Accumulate(Telemetry::HTTP_CONNECTION_ENTRY_CACHE_HIT_1,
ent->mUsedForConnection);
ent->mUsedForConnection = true;
}
Telemetry::Accumulate(Telemetry::HTTP_CONNECTION_ENTRY_CACHE_HIT_1,
dnsAndSock->mEnt->mUsedForConnection);
dnsAndSock->mEnt->mUsedForConnection = true;
nsCOMPtr<nsIOutputStream> sout;
rv = socketTransport->OpenOutputStream(nsITransport::OPEN_UNBUFFERED, 0, 0,
@ -1221,14 +1252,14 @@ nsresult DnsAndConnectSocket::TransportSetup::ResolveHost(
nsresult rv = dns->AsyncResolveNative(
mHost, nsIDNSService::RESOLVE_TYPE_DEFAULT, mDnsFlags, nullptr,
dnsAndSock, gSocketTransportService,
dnsAndSock->mConnInfo->GetOriginAttributes(),
dnsAndSock->mEnt->mConnInfo->GetOriginAttributes(),
getter_AddRefs(mDNSRequest));
if (NS_FAILED(rv) && (mDnsFlags & nsIDNSService::RESOLVE_IP_HINT)) {
mDnsFlags &= ~nsIDNSService::RESOLVE_IP_HINT;
return dns->AsyncResolveNative(
mHost, nsIDNSService::RESOLVE_TYPE_DEFAULT, mDnsFlags, nullptr,
dnsAndSock, gSocketTransportService,
dnsAndSock->mConnInfo->GetOriginAttributes(),
dnsAndSock->mEnt->mConnInfo->GetOriginAttributes(),
getter_AddRefs(mDNSRequest));
}
@ -1242,7 +1273,7 @@ nsresult DnsAndConnectSocket::TransportSetup::OnLookupComplete(
mDNSRecord = do_QueryInterface(rec);
MOZ_ASSERT(mDNSRecord);
if (dnsAndSock->mConnInfo->IsHttp3()) {
if (dnsAndSock->mEnt->mConnInfo->IsHttp3()) {
mState = TransportSetup::TransportSetupState::RESOLVED;
return status;
} else {

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

@ -52,17 +52,19 @@ class DnsAndConnectSocket final : public nsIOutputStreamCallback,
NS_DECL_NSINAMED
NS_DECL_NSIDNSLISTENER
DnsAndConnectSocket(nsHttpConnectionInfo* ci, nsAHttpTransaction* trans,
DnsAndConnectSocket(ConnectionEntry* ent, nsAHttpTransaction* trans,
uint32_t caps, bool speculative, bool isFromPredictor,
bool urgentStart);
[[nodiscard]] nsresult Init(ConnectionEntry* ent);
[[nodiscard]] nsresult Init();
void Abandon();
double Duration(TimeStamp epoch);
void CloseTransports(nsresult error);
bool IsSpeculative() { return mSpeculative; }
bool IsFromPredictor() { return mIsFromPredictor; }
bool Allow1918() { return mAllow1918; }
void SetAllow1918(bool val) { mAllow1918 = val; }
@ -199,7 +201,7 @@ class DnsAndConnectSocket final : public nsIOutputStreamCallback,
bool removeWhenFound);
void CheckProxyConfig();
nsresult SetupDnsFlags(ConnectionEntry* ent);
nsresult SetupDnsFlags();
nsresult SetupEvent(SetupEvents event);
RefPtr<nsAHttpTransaction> mTransaction;
@ -240,7 +242,7 @@ class DnsAndConnectSocket final : public nsIOutputStreamCallback,
// transactions.
bool mFreeToUse = true;
RefPtr<nsHttpConnectionInfo> mConnInfo;
RefPtr<ConnectionEntry> mEnt;
nsCOMPtr<nsITimer> mSynTimer;
TransportSetup mBackupTransport;

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

@ -95,18 +95,24 @@ bool PendingTransactionInfo::IsAlreadyClaimedInitializingConn() {
return alreadyDnsAndSockOrWaitingForTLS;
}
nsWeakPtr PendingTransactionInfo::ForgetDnsAndConnectSocketAndActiveConn() {
nsWeakPtr dnsAndSock = mDnsAndSock;
void PendingTransactionInfo::AbandonDnsAndConnectSocketAndForgetActiveConn() {
// Abandon all DnsAndConnectSockets belonging to the given transaction.
RefPtr<DnsAndConnectSocket> dnsAndSock = do_QueryReferent(mDnsAndSock);
if (dnsAndSock) {
dnsAndSock->Abandon();
}
mDnsAndSock = nullptr;
mActiveConn = nullptr;
return dnsAndSock;
}
void PendingTransactionInfo::RememberDnsAndConnectSocket(
bool PendingTransactionInfo::TryClaimingDnsAndConnectSocket(
DnsAndConnectSocket* sock) {
mDnsAndSock =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(sock));
if (sock->Claim()) {
mDnsAndSock =
do_GetWeakReference(static_cast<nsISupportsWeakReference*>(sock));
return true;
}
return false;
}
bool PendingTransactionInfo::TryClaimingActiveConn(HttpConnectionBase* conn) {

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

@ -24,14 +24,11 @@ class PendingTransactionInfo final : public ARefBase {
// a connection in TLS handshake phase.
bool IsAlreadyClaimedInitializingConn();
// This function return a weak poointer to DnsAndConnectSocket.
// The pointer is used by the caller(ConnectionEntry) to remove the
// DnsAndConnectSocket from the internal list. PendingTransactionInfo
// cannot perform this opereation.
[[nodiscard]] nsWeakPtr ForgetDnsAndConnectSocketAndActiveConn();
void AbandonDnsAndConnectSocketAndForgetActiveConn();
// Remember associated DnsAndConnectSocket.
void RememberDnsAndConnectSocket(DnsAndConnectSocket* sock);
// Try to claim a halfOpen socket. We can only claim it if it is not
// claimed yet.
bool TryClaimingDnsAndConnectSocket(DnsAndConnectSocket* sock);
// Similar as above, but for a ActiveConn that is performing a TLS handshake
// and has only a NullTransaction associated.
bool TryClaimingActiveConn(HttpConnectionBase* conn);

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

@ -1232,15 +1232,15 @@ nsresult nsHttpConnectionMgr::MakeNewConnection(
if (AtActiveConnectionLimit(ent, trans->Caps()))
return NS_ERROR_NOT_AVAILABLE;
nsresult rv = ent->CreateDnsAndConnectSocket(
trans, trans->Caps(), false, false,
trans->ClassOfService() & nsIClassOfService::UrgentStart, true,
pendingTransInfo);
nsresult rv =
CreateTransport(ent, trans, trans->Caps(), false, false,
trans->ClassOfService() & nsIClassOfService::UrgentStart,
true, pendingTransInfo);
if (NS_FAILED(rv)) {
/* hard failure */
LOG(
("nsHttpConnectionMgr::MakeNewConnection [ci = %s trans = %p] "
"CreateDnsAndConnectSocket() hard failure.\n",
"CreateTransport() hard failure.\n",
ent->mConnInfo->HashKey().get(), trans));
trans->Close(rv);
if (rv == NS_ERROR_NOT_AVAILABLE) rv = NS_ERROR_FAILURE;
@ -1738,6 +1738,36 @@ void nsHttpConnectionMgr::RecvdConnect() {
ConditionallyStopTimeoutTick();
}
nsresult nsHttpConnectionMgr::CreateTransport(
ConnectionEntry* ent, nsAHttpTransaction* trans, uint32_t caps,
bool speculative, bool isFromPredictor, bool urgentStart, bool allow1918,
PendingTransactionInfo* pendingTransInfo) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread");
MOZ_ASSERT((speculative && !pendingTransInfo) ||
(!speculative && pendingTransInfo));
RefPtr<DnsAndConnectSocket> sock = new DnsAndConnectSocket(
ent, trans, caps, speculative, isFromPredictor, urgentStart);
if (speculative) {
sock->SetAllow1918(allow1918);
}
// The socket stream holds the reference to the half open
// socket - so if the stream fails to init the half open
// will go away.
nsresult rv = sock->Init();
NS_ENSURE_SUCCESS(rv, rv);
if (pendingTransInfo) {
DebugOnly<bool> claimed =
pendingTransInfo->TryClaimingDnsAndConnectSocket(sock);
MOZ_ASSERT(claimed);
}
ent->InsertIntoDnsAndConnectSockets(sock);
return NS_OK;
}
void nsHttpConnectionMgr::DispatchSpdyPendingQ(
nsTArray<RefPtr<PendingTransactionInfo>>& pendingQ, ConnectionEntry* ent,
HttpConnectionBase* connH2, HttpConnectionBase* connH3) {
@ -3268,7 +3298,7 @@ void nsHttpConnectionMgr::DoSpeculativeConnection(
Unused << aTrans->FetchHTTPSRR();
}
DebugOnly<nsresult> rv =
ent->CreateDnsAndConnectSocket(aTrans, aTrans->Caps(), true, isFromPredictor,
CreateTransport(ent, aTrans, aTrans->Caps(), true, isFromPredictor,
false, allow1918, nullptr);
MOZ_ASSERT(NS_SUCCEEDED(rv));
} else {
@ -3476,11 +3506,6 @@ nsHttpConnectionMgr::FindTransactionHelper(bool removeWhenFound,
return info.forget();
}
already_AddRefed<ConnectionEntry>
nsHttpConnectionMgr::FindConnectionEntry(const nsHttpConnectionInfo* ci) {
return mCT.Get(ci->HashKey());
}
nsHttpConnectionMgr* nsHttpConnectionMgr::AsHttpConnectionMgr() { return this; }
HttpConnectionMgrParent* nsHttpConnectionMgr::AsHttpConnectionMgrParent() {

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

@ -171,9 +171,6 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
already_AddRefed<PendingTransactionInfo> FindTransactionHelper(
bool removeWhenFound, ConnectionEntry* aEnt, nsAHttpTransaction* aTrans);
already_AddRefed<ConnectionEntry> FindConnectionEntry(
const nsHttpConnectionInfo* ci);
public:
static nsAHttpConnection* MakeConnectionHandle(HttpConnectionBase* aWrapped);
void RegisterOriginCoalescingKey(HttpConnectionBase*, const nsACString& host,
@ -258,6 +255,9 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
[[nodiscard]] nsresult ProcessNewTransaction(nsHttpTransaction*);
[[nodiscard]] nsresult EnsureSocketThreadTarget();
void ReportProxyTelemetry(ConnectionEntry* ent);
[[nodiscard]] nsresult CreateTransport(
ConnectionEntry*, nsAHttpTransaction*, uint32_t, bool, bool, bool, bool,
PendingTransactionInfo* pendingTransInfo);
void StartedConnect();
void RecvdConnect();