Skip to content

Commit

Permalink
Add timeout to async_connect operation
Browse files Browse the repository at this point in the history
If the network goes down during a async_connect, we may end up being
stuck forever in this function since there is no timeout to cancel it.

Signed-off-by: Alex Michon <[email protected]>
  • Loading branch information
amichon-kalray committed Jun 17, 2024
1 parent f7ac85f commit c99b93a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/asio_service.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,14 @@ class asio_rpc_client
send_timeout_ms,
std::placeholders::_1,
std::placeholders::_2 ) );
if (send_timeout_ms != 0) {
operation_timer_.expires_after
( std::chrono::duration_cast<std::chrono::nanoseconds>
( std::chrono::milliseconds( send_timeout_ms ) ) );
operation_timer_.async_wait( std::bind( &asio_rpc_client::cancel_socket,
this,
std::placeholders::_1 ) );
}
} else {
ptr<resp_msg> rsp;
ptr<rpc_exception> except
Expand Down Expand Up @@ -1477,6 +1485,7 @@ class asio_rpc_client
std::error_code err,
asio::ip::tcp::resolver::iterator itor)
{
operation_timer_.cancel();
if (!err) {
p_in( "%p connected to %s:%s (as a client)",
this, host_.c_str(), port_.c_str() );
Expand Down

0 comments on commit c99b93a

Please sign in to comment.