Bug 1715029 - Keep the transaction alive when we failed to process it, r=necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D119171
This commit is contained in:
Kershaw Chang 2021-07-12 21:41:53 +00:00
Родитель f2e1419d77
Коммит 956fb7a27d
3 изменённых файлов: 32 добавлений и 26 удалений

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

@ -3457,12 +3457,11 @@ void nsHttpConnectionMgr::MoveToWildCardConnEntry(
ent->MoveConnection(proxyConn, wcEnt); ent->MoveConnection(proxyConn, wcEnt);
} }
bool nsHttpConnectionMgr::MoveTransToNewConnEntry( bool nsHttpConnectionMgr::RemoveTransFromConnEntry(nsHttpTransaction* aTrans) {
nsHttpTransaction* aTrans, nsHttpConnectionInfo* aNewCI) {
MOZ_ASSERT(OnSocketThread(), "not on socket thread"); MOZ_ASSERT(OnSocketThread(), "not on socket thread");
LOG(("nsHttpConnectionMgr::MoveTransToNewConnEntry: trans=%p aNewCI=%s", LOG(("nsHttpConnectionMgr::RemoveTransFromConnEntry: trans=%p ci=%s", aTrans,
aTrans, aNewCI->HashKey().get())); aTrans->ConnectionInfo()->HashKey().get()));
// Step 1: Get the transaction's connection entry. // Step 1: Get the transaction's connection entry.
ConnectionEntry* entry = mCT.GetWeak(aTrans->ConnectionInfo()->HashKey()); ConnectionEntry* entry = mCT.GetWeak(aTrans->ConnectionInfo()->HashKey());
@ -3471,14 +3470,7 @@ bool nsHttpConnectionMgr::MoveTransToNewConnEntry(
} }
// Step 2: Try to find the undispatched transaction. // Step 2: Try to find the undispatched transaction.
if (!entry->RemoveTransFromPendingQ(aTrans)) { return entry->RemoveTransFromPendingQ(aTrans);
return false;
}
// Step 3: Add the transaction.
aTrans->UpdateConnectionInfo(aNewCI);
Unused << ProcessNewTransaction(aTrans);
return true;
} }
void nsHttpConnectionMgr::IncreaseNumDnsAndConnectSockets() { void nsHttpConnectionMgr::IncreaseNumDnsAndConnectSockets() {

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

@ -69,11 +69,12 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
nsHttpConnectionInfo* wildcardCI, nsHttpConnectionInfo* wildcardCI,
HttpConnectionBase* conn); HttpConnectionBase* conn);
// Move a transaction from the pendingQ of it's connection entry to another // Remove a transaction from the pendingQ of it's connection entry. Returns
// one. Returns true if the transaction is moved successfully, otherwise // true if the transaction is removed successfully, otherwise returns false.
// returns false. bool RemoveTransFromConnEntry(nsHttpTransaction* aTrans);
bool MoveTransToNewConnEntry(nsHttpTransaction* aTrans,
nsHttpConnectionInfo* aNewCI); // Directly dispatch the transaction or insert it in to the pendingQ.
[[nodiscard]] nsresult ProcessNewTransaction(nsHttpTransaction* aTrans);
// This is used to force an idle connection to be closed and removed from // This is used to force an idle connection to be closed and removed from
// the idle connection list. It is called when the idle connection detects // the idle connection list. It is called when the idle connection detects
@ -260,7 +261,6 @@ class nsHttpConnectionMgr final : public HttpConnectionMgrShell,
uint32_t, uint32_t,
HttpConnectionBase*, HttpConnectionBase*,
int32_t); int32_t);
[[nodiscard]] nsresult ProcessNewTransaction(nsHttpTransaction*);
[[nodiscard]] nsresult EnsureSocketThreadTarget(); [[nodiscard]] nsresult EnsureSocketThreadTarget();
void ReportProxyTelemetry(ConnectionEntry* ent); void ReportProxyTelemetry(ConnectionEntry* ent);
void StartedConnect(); void StartedConnect();

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

@ -3026,6 +3026,8 @@ nsresult nsHttpTransaction::OnHTTPSRRAvailable(
return NS_OK; return NS_OK;
} }
RefPtr<nsHttpTransaction> deleteProtector(this);
uint32_t receivedStage = HTTPSSVC_NO_USABLE_RECORD; uint32_t receivedStage = HTTPSSVC_NO_USABLE_RECORD;
// Make sure we set the correct value to |mHTTPSSVCReceivedStage|, since we // Make sure we set the correct value to |mHTTPSSVCReceivedStage|, since we
// also use this value to indicate whether HTTPS RR is used or not. // also use this value to indicate whether HTTPS RR is used or not.
@ -3094,13 +3096,22 @@ nsresult nsHttpTransaction::OnHTTPSRRAvailable(
RefPtr<nsHttpConnectionInfo> newInfo = RefPtr<nsHttpConnectionInfo> newInfo =
mConnInfo->CloneAndAdoptHTTPSSVCRecord(svcbRecord); mConnInfo->CloneAndAdoptHTTPSSVCRecord(svcbRecord);
bool needFastFallback = newInfo->IsHttp3(); bool needFastFallback = newInfo->IsHttp3();
if (!gHttpHandler->ConnMgr()->MoveTransToNewConnEntry(this, newInfo)) { bool foundInPendingQ =
// MoveTransToNewConnEntry() returning fail means this transaction is gHttpHandler->ConnMgr()->RemoveTransFromConnEntry(this);
// not in the connection entry's pending queue. This could happen if
// OnLookupComplete() is called before this transaction is added in the // Adopt the new connection info, so this transaction will be added into the
// queue. We still need to update the connection info, so this transaction // new connection entry.
// can be added to the right connection entry.
UpdateConnectionInfo(newInfo); UpdateConnectionInfo(newInfo);
// If this transaction is sucessfully removed from a connection entry, we call
// ProcessNewTransaction to process it immediately.
// If not, this means that nsHttpTransaction::OnHTTPSRRAvailable happens
// before ProcessNewTransaction and this transaction will be processed later.
if (foundInPendingQ) {
if (NS_FAILED(gHttpHandler->ConnMgr()->ProcessNewTransaction(this))) {
LOG(("Failed to process this transaction."));
return NS_ERROR_FAILURE;
}
} }
// In case we already have mHttp3BackupTimer, cancel it. // In case we already have mHttp3BackupTimer, cancel it.
@ -3294,7 +3305,7 @@ void nsHttpTransaction::HandleFallback(
aFallbackConnInfo->HashKey().get())); aFallbackConnInfo->HashKey().get()));
bool foundInPendingQ = bool foundInPendingQ =
gHttpHandler->ConnMgr()->MoveTransToNewConnEntry(this, aFallbackConnInfo); gHttpHandler->ConnMgr()->RemoveTransFromConnEntry(this);
if (!foundInPendingQ) { if (!foundInPendingQ) {
MOZ_ASSERT(false, "transaction not in entry"); MOZ_ASSERT(false, "transaction not in entry");
return; return;
@ -3305,6 +3316,9 @@ void nsHttpTransaction::HandleFallback(
if (seekable) { if (seekable) {
seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0); seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
} }
UpdateConnectionInfo(aFallbackConnInfo);
Unused << gHttpHandler->ConnMgr()->ProcessNewTransaction(this);
} }
NS_IMETHODIMP NS_IMETHODIMP