@@ -631,7 +631,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
631631 m_context->m_timer .reset ();
632632 // // Replace the connection. This causes old connection object to go out of scope.
633633 auto client = std::static_pointer_cast<asio_client>(m_context->m_http_client );
634- m_context->m_connection = client->obtain_connection (m_context->m_request );
634+ try
635+ {
636+ m_context->m_connection = client->obtain_connection (m_context->m_request );
637+ }
638+ catch (...)
639+ {
640+ m_context->report_exception (std::current_exception ());
641+ return ;
642+ }
635643
636644 auto endpoint = *endpoints;
637645 m_context->m_connection ->async_connect (endpoint,
@@ -688,7 +696,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
688696 return ;
689697 }
690698
691- m_context->upgrade_to_ssl ();
699+ try
700+ {
701+ m_context->upgrade_to_ssl ();
702+ }
703+ catch (...)
704+ {
705+ m_context->report_exception (std::current_exception ());
706+ return ;
707+ }
692708
693709 m_ssl_tunnel_established (m_context);
694710 }
@@ -1009,7 +1025,15 @@ class asio_context final : public request_context, public std::enable_shared_fro
10091025 {
10101026 // Replace the connection. This causes old connection object to go out of scope.
10111027 auto client = std::static_pointer_cast<asio_client>(m_http_client);
1012- m_connection = client->obtain_connection (m_request);
1028+ try
1029+ {
1030+ m_connection = client->obtain_connection (m_request);
1031+ }
1032+ catch (...)
1033+ {
1034+ request_context::report_exception (std::current_exception ());
1035+ return ;
1036+ }
10131037
10141038 auto endpoint = *endpoints;
10151039 m_connection->async_connect (
@@ -1330,7 +1354,16 @@ class asio_context final : public request_context, public std::enable_shared_fro
13301354 // Create a new context and copy the request object, completion event and
13311355 // cancellation registration to maintain the old state.
13321356 // This also obtains a new connection from pool.
1333- auto new_ctx = create_request_context (m_http_client, m_request);
1357+ std::shared_ptr<request_context> new_ctx;
1358+ try
1359+ {
1360+ new_ctx = create_request_context (m_http_client, m_request);
1361+ }
1362+ catch (...)
1363+ {
1364+ report_exception (std::current_exception ());
1365+ return ;
1366+ }
13341367
13351368 // If the request contains a valid instream, we try to rewind it to
13361369 // replay the just-failed request. Otherwise we assume that no data
@@ -1940,7 +1973,15 @@ void asio_client::send_request(const std::shared_ptr<request_context>& request_c
19401973pplx::task<http_response> asio_client::propagate (http_request request)
19411974{
19421975 auto self = std::static_pointer_cast<_http_client_communicator>(shared_from_this ());
1943- auto context = details::asio_context::create_request_context (self, request);
1976+ std::shared_ptr<request_context> context;
1977+ try
1978+ {
1979+ context = details::asio_context::create_request_context (self, request);
1980+ }
1981+ catch (...)
1982+ {
1983+ return pplx::task_from_exception<http_response>(std::current_exception ());
1984+ }
19441985
19451986 // Use a task to externally signal the final result and completion of the task.
19461987 auto result_task = pplx::create_task (context->m_request_completion );
0 commit comments