From d9884eefa109e076276f391ceb1aa589d54653dd Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Thu, 21 Aug 2025 10:54:00 +0200 Subject: [PATCH] improves PeerImp logging --- src/xrpld/overlay/detail/PeerImp.cpp | 27 +++-------------------- src/xrpld/overlay/detail/PeerImp.h | 33 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 40ee6320b8..04478412d3 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -625,23 +625,14 @@ PeerImp::tryAsyncShutdown() return; if (readInProgress_ || writeInProgress_) - { - JLOG(journal_.debug()) - << "tryAsyncShutdown: waiting - read: " << readInProgress_ - << " write: " << writeInProgress_; return; - } shutdownStarted_ = true; XRPL_ASSERT( !readInProgress_ && !writeInProgress_, - "ripple::PeerImp::shutdown: read and write not in progress"); + "ripple::PeerImp::tryAsyncShutdown : read and write not in progress"); - JLOG(journal_.debug()) << "tryAsyncShutdown: read: " << readInProgress_ - << " write: " << writeInProgress_ - << " shutdown: " << shutdown_ - << " shutdownInProgress: " << shutdownStarted_; setTimer(); // gracefully shutdown the SSL socket, performing a shutdown handshake @@ -672,7 +663,6 @@ void PeerImp::onShutdown(error_code ec) { cancelTimer(); - JLOG(journal_.debug()) << "onShutdown"; if (ec) { // - eof: the stream was cleanly closed @@ -683,7 +673,7 @@ PeerImp::onShutdown(error_code ec) if (ec != boost::asio::error::eof && ec != boost::asio::error::operation_aborted) { - JLOG(journal_.warn()) << "onShutdown: " << ec.message(); + JLOG(journal_.debug()) << "onShutdown: " << ec.message(); } } @@ -967,11 +957,7 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred) } if (ec == boost::asio::error::operation_aborted) - { - JLOG(journal_.debug()) << "onReadMessage: aborted"; - return tryAsyncShutdown(); - } return fail("onReadMessage", ec); } @@ -1025,11 +1011,6 @@ PeerImp::onReadMessage(error_code ec, std::size_t bytes_transferred) XRPL_ASSERT( !shutdownStarted_, "ripple::PeerImp::onReadMessage : shutdown started"); - JLOG(journal_.debug()) << "onReadMessage: read: " << readInProgress_ - << " write: " << writeInProgress_ - << " shutdown: " << shutdown_ - << " shutdownInProgress: " << shutdownStarted_; - // Timeout on writes only stream_.async_read_some( read_buffer_.prepare(std::max(Tuning::readBufferBytes, hint)), @@ -1050,16 +1031,14 @@ PeerImp::onWriteMessage(error_code ec, std::size_t bytes_transferred) "ripple::PeerImp::onWriteMessage : strand in this thread"); writeInProgress_ = false; + if (!socket_.is_open()) return; if (ec) { if (ec == boost::asio::error::operation_aborted) - { - JLOG(journal_.debug()) << "onWriteMessage: aborted"; return tryAsyncShutdown(); - } return fail("onWriteMessage", ec); } diff --git a/src/xrpld/overlay/detail/PeerImp.h b/src/xrpld/overlay/detail/PeerImp.h index 9d79c30d87..a45fc99079 100644 --- a/src/xrpld/overlay/detail/PeerImp.h +++ b/src/xrpld/overlay/detail/PeerImp.h @@ -175,10 +175,10 @@ private: http_response_type response_; boost::beast::http::fields const& headers_; std::queue> send_queue_; - std::atomic shutdown_ = false; - std::atomic shutdownStarted_ = false; - std::atomic readInProgress_ = false; - std::atomic writeInProgress_ = false; + bool shutdown_ = false; + bool shutdownStarted_ = false; + bool readInProgress_ = false; + bool writeInProgress_ = false; int large_sendq_ = 0; std::unique_ptr load_event_; // The highest sequence of each PublisherList that has @@ -474,23 +474,30 @@ private: void fail(std::string const& reason); - /** - * @brief Initiates a graceful, timed, asynchronous SSL shutdown. + /** @brief Initiates the peer disconnection sequence. * - * This function begins the process of closing the peer connection securely. - * It first sets a timer to prevent the shutdown from hanging - * indefinitely. It then calls `async_shutdown` to perform the SSL shutdown - * handshake. The completion of this operation is handled by the - * `onShutdown` callback. + * This is the primary entry point to start closing a peer connection. It + * marks the peer for shutdown and cancels any outstanding asynchronous + * operations. This cancellation allows the graceful shutdown to proceed + * once the handlers for the cancelled operations have completed. * - * @note This function must be called from within the object's strand. - * It is safe to call if the socket is already closed. + * @note This method must be called on the peer's strand. */ void shutdown(); + /** @brief Attempts to perform a graceful SSL shutdown if conditions are + * met. + * + * This helper function checks if the peer is in a state where a graceful + * SSL shutdown can be performed (i.e., shutdown has been requested and no + * I/O operations are currently in progress). + * + * @note This method must be called on the peer's strand. + */ void tryAsyncShutdown(); + /** * @brief Handles the completion of the asynchronous SSL shutdown. *