diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-01-25 21:33:40 +0100 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-01-25 21:33:40 +0100 |
commit | 7c0742aa2b0b548bf99abe43c1a0410a11576893 (patch) | |
tree | c184ed96c1db08b88541b6e4b07bed0c707f3faa /lib/connection.cpp | |
parent | a4e78956f105875625b572d8b98459ffa86fafe5 (diff) | |
download | libquotient-7c0742aa2b0b548bf99abe43c1a0410a11576893.tar.gz libquotient-7c0742aa2b0b548bf99abe43c1a0410a11576893.zip |
Connection: stop login flows job before resolving
This avoids a corner case when a login flows job finishes (or worse,
goes for a retry) while the homeserver is (being) resolved, yielding
the Connection object in an inconsistent state to the client.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 3ed71bb4..0fb2d003 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -133,6 +133,11 @@ public: != "json"; bool lazyLoading = false; + /// \brief Stop resolving and login flows jobs, and clear login flows + /// + /// Prepares the class to set or resolve a new homeserver + void clearResolvingContext(); + /** \brief Check the homeserver and resolve it if needed, before connecting * * A single entry for functions that need to check whether the homeserver @@ -270,8 +275,7 @@ Connection::~Connection() void Connection::resolveServer(const QString& mxid) { - if (isJobRunning(d->resolverJob)) - d->resolverJob->abandon(); + d->clearResolvingContext(); auto maybeBaseUrl = QUrl::fromUserInput(serverPart(mxid)); maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http" @@ -1530,13 +1534,19 @@ QByteArray Connection::generateTxnId() const return d->data->generateTxnId(); } +void Connection::Private::clearResolvingContext() +{ + if (isJobRunning(resolverJob)) + resolverJob->abandon(); + if (isJobRunning(loginFlowsJob)) + loginFlowsJob->abandon(); + loginFlows.clear(); + +} + void Connection::setHomeserver(const QUrl& url) { - if (isJobRunning(d->resolverJob)) - d->resolverJob->abandon(); - if (isJobRunning(d->loginFlowsJob)) - d->loginFlowsJob->abandon(); - d->loginFlows.clear(); + d->clearResolvingContext(); if (homeserver() != url) { d->data->setBaseUrl(url); |