Try to fix #119
This commit is contained in:
@@ -71,7 +71,21 @@ void ConnectionLoader::loadConnection()
|
|||||||
|
|
||||||
void ConnectionLoader::loadProgress()
|
void ConnectionLoader::loadProgress()
|
||||||
{
|
{
|
||||||
QTimer::singleShot(1, [=]() { this->ShowProgress(); });
|
bool failed = false;
|
||||||
|
QTimer::singleShot(1, [=]() mutable {
|
||||||
|
// continually retry ShowProgress() until it succeeds
|
||||||
|
// by running without an exception
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
this->ShowProgress();
|
||||||
|
failed = false;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEBUG("caught exception " << e.what() );
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
} while (failed);
|
||||||
|
|
||||||
|
});
|
||||||
if (!Settings::getInstance()->isHeadless())
|
if (!Settings::getInstance()->isHeadless())
|
||||||
d->exec();
|
d->exec();
|
||||||
}
|
}
|
||||||
@@ -85,7 +99,7 @@ void ConnectionLoader::ShowProgress()
|
|||||||
|
|
||||||
auto connection = makeConnection(config);
|
auto connection = makeConnection(config);
|
||||||
auto me = this;
|
auto me = this;
|
||||||
qDebug() << __func__ << ": server=" << config->server << " connection=" << connection << " me=" << me;
|
DEBUG("server=" << config->server << " connection=" << connection << " me=" << me);
|
||||||
|
|
||||||
isSyncing = new QAtomicInteger<bool>();
|
isSyncing = new QAtomicInteger<bool>();
|
||||||
isSyncing->store(true);
|
isSyncing->store(true);
|
||||||
@@ -107,27 +121,30 @@ void ConnectionLoader::ShowProgress()
|
|||||||
// Check the sync status
|
// Check the sync status
|
||||||
if (isSyncing != nullptr && isSyncing->load()) {
|
if (isSyncing != nullptr && isSyncing->load()) {
|
||||||
// Get the sync status
|
// Get the sync status
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection->doRPC("syncstatus", "", [=](json reply) {
|
connection->doRPC("syncstatus", "", [=](json reply) {
|
||||||
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end())
|
if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
|
||||||
|
|
||||||
{
|
|
||||||
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
|
||||||
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
|
||||||
me->showInformation(
|
me->showInformation(
|
||||||
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
|
"Syncing... " + QString::number(synced) + " / " + QString::number(total)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
}, [=](QString err) {
|
||||||
[=](QString err) {
|
DEBUG("Sync error " << err);
|
||||||
qDebug() << "Sync error" << err;
|
// We may have gotten "Unexpected compression flag: 60"
|
||||||
|
// or some other error, so let's try another server
|
||||||
|
config->server = Settings::getRandomServer();
|
||||||
|
DEBUG("Changed server to " << config->server );
|
||||||
});
|
});
|
||||||
}catch (...)
|
} catch (const std::exception& e) {
|
||||||
{
|
DEBUG("syncstatus exception: " << e.what() );
|
||||||
main->logger->write("catch sync progress reply");
|
main->logger->write("catch sync progress reply");
|
||||||
}
|
|
||||||
|
|
||||||
|
// rethrow exception so loadProgress can catch
|
||||||
|
// it and retry the entire ShowProgress() function again
|
||||||
|
throw new std::runtime_error(std::string("syncstatus failed"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user