Skip to content

Commit abc2753

Browse files
committed
Reduce size of race condition in asio_client. In the future, the entire timeout interaction needs to be reworked to remove it entirely.
1 parent 2e99d10 commit abc2753

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Release/src/http/client/http_client_asio.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ class asio_context : public request_context, public std::enable_shared_from_this
464464
m_context->m_timer.reset();
465465
auto endpoint = *endpoints;
466466
m_context->m_connection->async_connect(endpoint, boost::bind(&ssl_proxy_tunnel::handle_tcp_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints));
467+
468+
// TODO: refactor all interactions with the timeout_timer to avoid racing
469+
if (m_context->m_timer.has_timedout())
470+
{
471+
m_context->m_connection->close();
472+
}
467473
}
468474
}
469475

@@ -876,6 +882,12 @@ class asio_context : public request_context, public std::enable_shared_from_this
876882
m_timer.reset();
877883
auto endpoint = *endpoints;
878884
m_connection->async_connect(endpoint, boost::bind(&asio_context::handle_connect, shared_from_this(), boost::asio::placeholders::error, ++endpoints));
885+
886+
// TODO: refactor all interactions with the timeout_timer to avoid racing
887+
if (m_timer.has_timedout())
888+
{
889+
m_connection->close();
890+
}
879891
}
880892
}
881893

@@ -1479,7 +1491,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
14791491
#else
14801492
std::chrono::microseconds m_duration;
14811493
#endif
1482-
timer_state m_state;
1494+
std::atomic<timer_state> m_state;
14831495
std::weak_ptr<asio_context> m_ctx;
14841496
boost::asio::steady_timer m_timer;
14851497
};

0 commit comments

Comments
 (0)