From bfdda1f1af7e4bc42dc1a4e10985e6c152dad8bd Mon Sep 17 00:00:00 2001 From: Duke Date: Thu, 30 Mar 2023 16:39:10 -0700 Subject: [PATCH] Try really hard to make sync RPC finish --- src/connection.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 6d33e9a..2d3c1a2 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -241,8 +241,27 @@ void ConnectionLoader::doAutoConnect() syncTimer->deleteLater(); // When sync is done, set the connection this->doRPCSetConnection(connection); - }, [=](auto) { + }, [=](auto) mutable { DEBUG("sync rpc error! server=" << config->server); + // continually retry sync RPC until it succeeds + // change server each time it fails + bool failed = true; + do { + config->server = Settings::getRandomServer(); + auto connection = makeConnection(config); + DEBUG("changed server to " << config->server); + connection->doRPC("sync", "", [=](auto) mutable { + DEBUG("sync success with server=" << config->server); + failed = false; + isSyncing->store(false); + // Cancel the timer + syncTimer->deleteLater(); + // When sync is done, set the connection + this->doRPCSetConnection(connection); + }, [=](auto) { + DEBUG("sync failed with server=" << config->server << " . continuing sync loop" ); + }); + } while (failed); }); // While it is syncing, we'll show the status updates while it is alive. @@ -261,12 +280,11 @@ void ConnectionLoader::doAutoConnect() } }, [=](QString err) { - DEBUG("Sync error" << err); + DEBUG("syncstatus error" << err); }); } catch (const std::exception& e) { DEBUG("caught exception from syncstatus: " << e.what()); } - } });