From 41ddfb7b477e3603daeec913585312d09d12828d Mon Sep 17 00:00:00 2001 From: Tyler Karaszewski Date: Wed, 31 Aug 2022 18:07:25 +0200 Subject: [PATCH] Handle exceptions thrown in _queueSynchronize --- sqlitecluster/SQLiteNode.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sqlitecluster/SQLiteNode.cpp b/sqlitecluster/SQLiteNode.cpp index adacf1148..41aa210be 100644 --- a/sqlitecluster/SQLiteNode.cpp +++ b/sqlitecluster/SQLiteNode.cpp @@ -1452,12 +1452,22 @@ void SQLiteNode::_onMESSAGE(SQLitePeer* peer, const SData& message) { SData response("SYNCHRONIZE_RESPONSE"); SQLiteScopedHandle dbScope(*_dbPool, _dbPool->getIndex()); SQLite& db = dbScope.db(); - _queueSynchronize(this, peer, db, response, false); + try { + _queueSynchronize(this, peer, db, response, false); + + // The following two lines are copied from `_sendToPeer`. + response["CommitCount"] = to_string(db.getCommitCount()); + response["Hash"] = db.getCommittedHash(); + peer->sendMessage(response); + } catch (const SException& e) { + // This is the same handling as at the bottom of _onMESSAGE. + PWARN("Error processing message '" << message.methodLine << "' (" << e.what() << "), reconnecting."); + SData reconnect("RECONNECT"); + reconnect["Reason"] = e.what(); + peer->sendMessage(reconnect.serialize()); + peer->shutdownSocket(); + } - // The following two lines are copied from `_sendToPeer`. - response["CommitCount"] = to_string(db.getCommitCount()); - response["Hash"] = db.getCommittedHash(); - peer->sendMessage(response); _pendingSynchronizeResponses--; }).detach(); }