Skip to content

Commit

Permalink
RXI-880 fix shutdown issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Jan 24, 2024
1 parent e715467 commit e9e6253
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/xbwd/app/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ BasicApp::~BasicApp()
work_.reset();
io_service_.stop();
for (auto& t : threads_)
t.join();
if (t.joinable())
t.join();
}

App::App(
Expand Down
9 changes: 4 additions & 5 deletions src/xbwd/client/ChainListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ ChainListener::ChainListener(
{
}

// destructor must be defined after WebsocketClient size is known (i.e. it can
// not be defaulted in the header or the unique_ptr declaration of
// WebsocketClient won't work)
ChainListener::~ChainListener() = default;

void
ChainListener::init(boost::asio::io_service& ios, beast::IP::Endpoint const& ip)
{
Expand Down Expand Up @@ -151,7 +146,11 @@ void
ChainListener::shutdown()
{
if (wsClient_)
{
wsClient_->shutdown();
// wsClient has shared_ptr to ChainListener
wsClient_.reset();
}
}

std::uint32_t
Expand Down
2 changes: 1 addition & 1 deletion src/xbwd/client/ChainListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ChainListener : public std::enable_shared_from_this<ChainListener>
std::optional<ripple::AccountID> signAccount,
beast::Journal j);

virtual ~ChainListener();
~ChainListener() = default;

void
init(boost::asio::io_service& ios, beast::IP::Endpoint const& ip);
Expand Down
5 changes: 4 additions & 1 deletion src/xbwd/client/WebsocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ WebsocketClient::cleanup()
void
WebsocketClient::shutdown()
{
if (isShutdown_)
return;
cleanup();
std::unique_lock l{shutdownM_};
shutdownCv_.wait(l, [this] { return isShutdown_.load(); });
if (!isShutdown_)
shutdownCv_.wait(l, [this] { return isShutdown_.load(); });
}

WebsocketClient::WebsocketClient(
Expand Down
3 changes: 2 additions & 1 deletion src/xbwd/federator/Federator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ Federator::stop()
}

for (int i = 0; i < lt_last; ++i)
threads_[i].join();
if (threads_[i].joinable())
threads_[i].join();
running_ = false;
}
}
Expand Down

0 comments on commit e9e6253

Please sign in to comment.