From 17313dae294007d3689e86863c6c2050677cb90e Mon Sep 17 00:00:00 2001 From: Savinda Senevirathne Date: Fri, 11 Dec 2020 16:36:04 +0530 Subject: [PATCH] Comm session race conditions. (#192) --- src/comm/comm_server.hpp | 4 ++-- src/comm/comm_session.cpp | 8 ++++---- src/comm/comm_session.hpp | 2 +- src/ledger.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/comm/comm_server.hpp b/src/comm/comm_server.hpp index 51a17f1f..02dbe677 100644 --- a/src/comm/comm_server.hpp +++ b/src/comm/comm_server.hpp @@ -88,7 +88,7 @@ namespace comm itr->check_last_activity_rules(); if (itr->state == SESSION_STATE::MUST_CLOSE) - itr->close(true); + itr->close(); if (itr->state == SESSION_STATE::CLOSED) itr = sessions.erase(itr); @@ -101,7 +101,7 @@ namespace comm // Close and erase all sessions. for (T &session : sessions) - session.close(false); + session.close(); sessions.clear(); diff --git a/src/comm/comm_session.cpp b/src/comm/comm_session.cpp index 8112864a..3cbb91ea 100644 --- a/src/comm/comm_session.cpp +++ b/src/comm/comm_session.cpp @@ -207,13 +207,13 @@ namespace comm * Close the connection and wrap up any session processing threads. * This will be only called by the global comm_server thread. */ - void comm_session::close(const bool invoke_handler) + void comm_session::close() { if (state == SESSION_STATE::CLOSED) return; - if (invoke_handler) - handle_close(); + // Invoking the handler of the derived class for cleanups. + handle_close(); state = SESSION_STATE::CLOSED; @@ -240,7 +240,7 @@ namespace comm // Sessions use pubkey hex as unique id (skipping first 2 bytes key type prefix). return uniqueid.substr(2, 10) + (is_inbound ? ":in" : ":out"); } - + return uniqueid + (is_inbound ? ":in" : ":out"); } diff --git a/src/comm/comm_session.hpp b/src/comm/comm_session.hpp index 2b64bb70..684d5a6a 100644 --- a/src/comm/comm_session.hpp +++ b/src/comm/comm_session.hpp @@ -66,7 +66,7 @@ namespace comm void process_outbound_msg_queue(); void check_last_activity_rules(); void mark_for_closure(); - void close(const bool invoke_handler = true); + void close(); void mark_as_verified(); virtual const std::string display_name(); diff --git a/src/ledger.cpp b/src/ledger.cpp index 78c0057a..9c82d514 100644 --- a/src/ledger.cpp +++ b/src/ledger.cpp @@ -855,12 +855,12 @@ namespace ledger { throw "Lcl file parsing error in file " + b + " in " + conf::ctx.hist_dir; } - const std::string_view extension_a = util::fetch_file_extension(conf::ctx.hist_dir + a); + const std::string_view extension_a = util::fetch_file_extension(a); if (extension_a != ".lcl") { throw "Found invalid file extension: " + std::string(extension_a) + " for lcl file " + a + " in " + conf::ctx.hist_dir; } - const std::string_view extension_b = util::fetch_file_extension(conf::ctx.hist_dir + b); + const std::string_view extension_b = util::fetch_file_extension(b); if (extension_b != ".lcl") { throw "Found invalid file extension: " + std::string(extension_b) + " for lcl file " + b + " in " + conf::ctx.hist_dir;