HDFS-11436: libhdfs++: Fix race condition in ScopedResolver. Contributed by James Clampffer.
This commit is contained in:
parent
8783461e2e
commit
606d20c6c0
|
@ -109,13 +109,14 @@ class ScopedResolver {
|
||||||
|
|
||||||
// Now set up the promise, set it in async_resolve's callback
|
// Now set up the promise, set it in async_resolve's callback
|
||||||
result_status_ = std::make_shared<std::promise<Status>>();
|
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
|
// 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) {
|
if(!ec) {
|
||||||
std::copy(out, ::asio::ip::tcp::resolver::iterator(), std::back_inserter(endpoints_));
|
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);
|
resolver_.async_resolve(query_, callback);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue