diff --git a/include/ChatPage.h b/include/ChatPage.h
index 4c8ed05b50bffe2215319c15a7e463146b8b1054..bac83ece39e9c499bbc7bc2e6fca64e0ea7b7401 100644
--- a/include/ChatPage.h
+++ b/include/ChatPage.h
@@ -56,6 +56,7 @@ signals:
         void changeWindowTitle(const QString &msg);
         void unreadMessages(int count);
         void showNotification(const QString &msg);
+        void showLoginPage(const QString &msg);
 
 private slots:
         void showUnreadMessageNotification(int count);
@@ -74,6 +75,8 @@ private:
         void updateTypingUsers(const QString &roomid, const QList<QString> &user_ids);
         void updateDisplayNames(const RoomState &state);
         void loadStateFromCache();
+        void deleteConfigs();
+        void resetUI();
 
         QHBoxLayout *topLayout_;
         Splitter *splitter;
@@ -121,4 +124,8 @@ private:
 
         // LMDB wrapper.
         QSharedPointer<Cache> cache_;
+
+        // If the number of failures exceeds a certain threshold we
+        // return to the login page.
+        int initialSyncFailures = 0;
 };
diff --git a/include/LoginPage.h b/include/LoginPage.h
index 5caa3f1ef1db7154c5a7d8eea3765cdd1e074ac9..88cffaf304afdafc6b918126e88c7b9dbd1aae85 100644
--- a/include/LoginPage.h
+++ b/include/LoginPage.h
@@ -43,6 +43,10 @@ public:
 signals:
         void backButtonClicked();
 
+public slots:
+        // Displays errors produced during the login.
+        void loginError(QString error_message);
+
 private slots:
         // Callback for the back button.
         void onBackButtonClicked();
@@ -56,9 +60,6 @@ private slots:
         // Callback for probing the manually entered server
         void onServerAddressEntered();
 
-        // Displays errors produced during the login.
-        void loginError(QString error_message);
-
         // Callback for errors produced during server probing
         void versionError(QString error_message);
 
diff --git a/include/MatrixClient.h b/include/MatrixClient.h
index 01e2c319efe3a3836df16e2811b8877737bf6acc..0185bf64ed139ac3ee2ba83af96c862543aa5c58 100644
--- a/include/MatrixClient.h
+++ b/include/MatrixClient.h
@@ -91,6 +91,7 @@ signals:
         // Returned profile data for the user's account.
         void getOwnProfileResponse(const QUrl &avatar_url, const QString &display_name);
         void initialSyncCompleted(const SyncResponse &response);
+        void initialSyncFailed(const QString &msg);
         void syncCompleted(const SyncResponse &response);
         void syncFailed(const QString &msg);
         void joinFailed(const QString &msg);
diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index d8280a4a6ad31e6bb69a81e60656a95032f97a42..cf78d8a1b6c385d97cb4e53fe506fd9c8c94edd7 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -29,6 +29,8 @@
 
 #include "StateEvent.h"
 
+constexpr int MAX_INITIAL_SYNC_FAILURES = 5;
+
 namespace events = matrix::events;
 
 ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
@@ -192,6 +194,24 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
                 SIGNAL(initialSyncCompleted(const SyncResponse &)),
                 this,
                 SLOT(initialSyncCompleted(const SyncResponse &)));
+        connect(client_.data(), &MatrixClient::initialSyncFailed, this, [=](const QString &msg) {
+                initialSyncFailures += 1;
+
+                if (initialSyncFailures >= MAX_INITIAL_SYNC_FAILURES) {
+                        initialSyncFailures = 0;
+
+                        deleteConfigs();
+
+                        emit showLoginPage(msg);
+                        emit contentLoaded();
+                        return;
+                }
+
+                qWarning() << msg;
+                qWarning() << "Retrying initial sync";
+
+                client_->initialSync();
+        });
         connect(client_.data(),
                 SIGNAL(syncCompleted(const SyncResponse &)),
                 this,
@@ -239,7 +259,29 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
 void
 ChatPage::logout()
 {
-        // Delete all config parameters.
+        deleteConfigs();
+
+        resetUI();
+
+        emit close();
+}
+
+void
+ChatPage::resetUI()
+{
+        room_avatars_.clear();
+        room_list_->clear();
+        settingsManager_.clear();
+        state_manager_.clear();
+        top_bar_->reset();
+        user_info_widget_->reset();
+        view_manager_->clearAll();
+        AvatarProvider::clear();
+}
+
+void
+ChatPage::deleteConfigs()
+{
         QSettings settings;
         settings.beginGroup("auth");
         settings.remove("");
@@ -253,21 +295,7 @@ ChatPage::logout()
 
         cache_->deleteData();
 
-        // Clear the environment.
-        room_list_->clear();
-        view_manager_->clearAll();
-
-        top_bar_->reset();
-        user_info_widget_->reset();
         client_->reset();
-
-        state_manager_.clear();
-        settingsManager_.clear();
-        room_avatars_.clear();
-
-        AvatarProvider::clear();
-
-        emit close();
 }
 
 void
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index f6276967ba1789f9011309212b25cc0620bd2d96..b6033eafa3cf17dae631bb9fe67f6850e742fc70 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -73,6 +73,10 @@ MainWindow::MainWindow(QWidget *parent)
         connect(
           chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
         connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
+        connect(chat_page_, &ChatPage::showLoginPage, this, [=](const QString &msg) {
+                login_page_->loginError(msg);
+                showLoginPage();
+        });
 
         connect(trayIcon_,
                 SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc
index e9e47fcb5ad3a900e2fe1a34ac5d73cadeabf446..4ececd0136f9edfe76dece42488c3ad3115371d1 100644
--- a/src/MatrixClient.cc
+++ b/src/MatrixClient.cc
@@ -221,7 +221,7 @@ MatrixClient::onInitialSyncResponse(QNetworkReply *reply)
         int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
         if (status == 0 || status >= 400) {
-                qWarning() << reply->errorString();
+                emit initialSyncFailed(reply->errorString());
                 return;
         }