Skip to content

Commit

Permalink
Fix deadlock in websocket server (#342)
Browse files Browse the repository at this point in the history
This is a rather dumb mistake. I think I left this in as a vestige of my
testing. However, the websocket client was refusing to reconnect thanks
to a deadlock caused by this variable.

Signed-off-by: Arjo Chakravarty <arjoc@google.com>
  • Loading branch information
arjo129 committed Apr 23, 2024
1 parent 6dfafa0 commit 69d778f
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions rmf_websocket/src/rmf_websocket/client/ClientWebSocketEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ websocketpp::lib::error_code ClientWebSocketEndpoint::connect()
{
websocketpp::lib::error_code ec;


_init = true;
_con = _endpoint->get_connection(_uri, ec);
RCLCPP_INFO(_node->get_logger(), "Attempting to connect to %s", _uri.c_str());
Expand All @@ -140,30 +139,25 @@ websocketpp::lib::error_code ClientWebSocketEndpoint::connect()
auto reconnect_socket = [this]()
{
// TODO(arjo) Parametrize the timeout.
using namespace std::chrono_literals;
if (!_reconnect_enqueued)
{
RCLCPP_ERROR(_node->get_logger(),
"Connection lost\n"
"> Reconnecting in 1s\n"
"> Host: %s", _uri.c_str());
_endpoint->stop_perpetual();
auto io_service = &_endpoint->get_io_service();
_endpoint = std::make_unique<WsClient>();
_endpoint->clear_access_channels(websocketpp::log::alevel::all);
_endpoint->clear_error_channels(websocketpp::log::elevel::all);
_endpoint->init_asio(io_service);
_endpoint->start_perpetual();
websocketpp::lib::error_code ec;

_endpoint->set_timer(1000, std::bind(&ClientWebSocketEndpoint::connect,
this));
_reconnect_enqueued = true;
}
RCLCPP_ERROR(_node->get_logger(),
"Connection lost\n"
"> Reconnecting in 1s\n"
"> Host: %s", _uri.c_str());
_endpoint->stop_perpetual();
auto io_service = &_endpoint->get_io_service();
_endpoint = std::make_unique<WsClient>();
_endpoint->clear_access_channels(websocketpp::log::alevel::all);
_endpoint->clear_error_channels(websocketpp::log::elevel::all);
_endpoint->init_asio(io_service);
_endpoint->start_perpetual();
websocketpp::lib::error_code ec;

_endpoint->set_timer(1000, std::bind(&ClientWebSocketEndpoint::connect,
this));

};
auto connected_cb = [this]()
{
_reconnect_enqueued = false;
_connection_cb();
};

Expand Down

0 comments on commit 69d778f

Please sign in to comment.