Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tcp::resolver data race in the asio backend and be defensive against empty results #1339

Merged
merged 3 commits into from
Feb 23, 2020

Conversation

BillyONeal
Copy link
Member

Move TCP resolver to asio_context rather than asio_client, as that type is not safe to touch from multiple threads. @vinniefalco confirmed over Twitter that constructing resolvers is cheap https://twitter.com/FalcoVinnie/status/1230780333613670401

…pe is not safe to touch from multiple threads.
@BillyONeal BillyONeal self-assigned this Feb 21, 2020
@BillyONeal BillyONeal changed the title Fix tcp::resolver data race in the asio backend Fix tcp::resolver data race in the asio backend and be defensive against empty results Feb 23, 2020
@@ -1050,6 +1050,10 @@ class asio_context final : public request_context, public std::enable_shared_fro
{
report_error("Error resolving address", ec, httpclient_errorcode_context::connect);
}
else if (endpoints == tcp::resolver::iterator())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yuck... raw iterator resolver API!

You are using a deprecated API I believe. If you can require a recent Asio, then you can work with results as a container and just check results.size() == 0. See:
https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/ip__basic_resolver_results.html

I would define BOOST_ASIO_NO_DEPRECATED and make sure you aren't using any deprecated APIs. You also don't need the query, use this overload of async_resolve:

https://www.boost.org/doc/libs/1_72_0/doc/html/boost_asio/reference/ip__basic_resolver/async_resolve/overload2.html

Note how there's individual host and service parameters instead of that annoying query type. And note that the completion handler receives a range instead of an iterator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can require a recent Asio

This has to work back at least as far as 1.58, since that's what Ubuntu 16.04 comes shipped with. Maybe even earlier depending on what RHEL and friends are bundling.

I would define BOOST_ASIO_NO_DEPRECATED and make sure you aren't using any deprecated APIs.

That's #1323 :)

This change is to unblock a specific high profile customer so I don't want to make any risky-for-dependencies changes at the same time. (And this isn't really a can of worms I'm going to open unless forced given cpprestsdk's current "effectively unfunded except for support of the Azure Storage SDK" status)

@BillyONeal BillyONeal merged commit 0886fcc into microsoft:master Feb 23, 2020
@BillyONeal BillyONeal deleted the tcp_resolver_race branch February 24, 2020 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants