HDFS-11436: libhdfs++: Fix race condition in ScopedResolver. Contributed by James Clampffer.

This commit is contained in:
James 2017-02-22 12:12:24 -05:00 committed by James Clampffer
parent 8783461e2e
commit 606d20c6c0
1 changed files with 3 additions and 2 deletions

View File

@ -109,13 +109,14 @@ class ScopedResolver {
// Now set up the promise, set it in async_resolve's callback
result_status_ = std::make_shared<std::promise<Status>>();
std::shared_ptr<std::promise<Status>> shared_result = result_status_;
// Callback to pull a copy of endpoints out of resolver and set promise
auto callback = [this](const asio::error_code &ec, ::asio::ip::tcp::resolver::iterator out) {
auto callback = [this, shared_result](const asio::error_code &ec, ::asio::ip::tcp::resolver::iterator out) {
if(!ec) {
std::copy(out, ::asio::ip::tcp::resolver::iterator(), std::back_inserter(endpoints_));
}
result_status_->set_value( ToStatus(ec) );
shared_result->set_value( ToStatus(ec) );
};
resolver_.async_resolve(query_, callback);
return true;