Skip to content

Commit

Permalink
httpsession: cancel other activities when closing (#48066)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges committed Sep 11, 2024
1 parent 83f84b4 commit 758f3bd
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions src/handler/httpsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class HttpSession::Private : public QObject
FilterStack *responseFilters;
QSet<QString> activeChannels;
int connectionSubscriptionMax;
bool needRemoveFromStats;
bool connectionStatsActive;
Callback<std::tuple<HttpSession *, const QString &>> subscribeCallback;
Callback<std::tuple<HttpSession *, const QString &>> unsubscribeCallback;
Callback<std::tuple<HttpSession *>> finishedCallback;
Expand Down Expand Up @@ -205,7 +205,7 @@ class HttpSession::Private : public QObject
pendingAction(0),
responseFilters(0),
connectionSubscriptionMax(_connectionSubscriptionMax),
needRemoveFromStats(true)
connectionStatsActive(true)
{
state = NotStarted;

Expand Down Expand Up @@ -237,16 +237,6 @@ class HttpSession::Private : public QObject
{
cleanup();

if(needRemoveFromStats)
{
ZhttpRequest::Rid rid = req->rid();
QByteArray cid = rid.first + ':' + rid.second;

stats->removeConnection(cid, false);
}

updateManager->unregisterSession(q);

timerConnection.disconnect();
timer->setParent(0);
timer->deleteLater();
Expand Down Expand Up @@ -361,7 +351,7 @@ class HttpSession::Private : public QObject
if(priority == HighPriority)
{
// switching to high priority
cleanupAction();
cancelAction();
state = Holding;
}
else
Expand Down Expand Up @@ -528,8 +518,17 @@ class HttpSession::Private : public QObject
private:
void cleanup()
{
cleanupOutReq();
cleanupAction();
cancelActivities();

if(connectionStatsActive)
{
connectionStatsActive = false;

ZhttpRequest::Rid rid = req->rid();
QByteArray cid = rid.first + ':' + rid.second;

stats->removeConnection(cid, false);
}
}

void cleanupOutReq()
Expand All @@ -542,7 +541,7 @@ class HttpSession::Private : public QObject
responseFilters = 0;
}

void cleanupAction()
void cancelAction()
{
if(pendingAction)
{
Expand All @@ -551,6 +550,19 @@ class HttpSession::Private : public QObject
}
}

void cancelActivities()
{
cleanupOutReq();
cancelAction();

publishQueue.clear();

timer->stop();
retryTimer->stop();

updateManager->unregisterSession(q);
}

void setupKeepAlive()
{
if(instruct.keepAliveTimeout >= 0)
Expand All @@ -573,9 +585,7 @@ class HttpSession::Private : public QObject
{
state = Closing;

publishQueue.clear();
timer->stop();
updateManager->unregisterSession(q);
cancelActivities();
}

void tryWriteFirstInstructResponse()
Expand Down Expand Up @@ -1065,12 +1075,11 @@ class HttpSession::Private : public QObject

void doFinish(bool retry = false)
{
cancelActivities();

ZhttpRequest::Rid rid = req->rid();
QByteArray cid = rid.first + ':' + rid.second;

cleanupOutReq();
cleanupAction();

QPointer<QObject> self = this;

QHashIterator<QString, Instruct::Channel> it(channels);
Expand All @@ -1089,7 +1098,7 @@ class HttpSession::Private : public QObject
// refresh before remove, to ensure transition
stats->refreshConnection(cid);

needRemoveFromStats = false;
connectionStatsActive = false;

int unreportedTime = stats->removeConnection(cid, true, adata.from);

Expand Down Expand Up @@ -1154,7 +1163,7 @@ class HttpSession::Private : public QObject
}
else
{
needRemoveFromStats = false;
connectionStatsActive = false;

stats->removeConnection(cid, false);
}
Expand Down Expand Up @@ -1308,7 +1317,7 @@ class HttpSession::Private : public QObject

retries = 0;

outReq.reset();
cleanupOutReq();

bool ok;
Instruct i = Instruct::fromResponse(responseData, &ok, &errorMessage);
Expand Down

0 comments on commit 758f3bd

Please sign in to comment.