Browse Source

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

James 8 years ago
parent
commit
606d20c6c0

+ 3 - 2
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/namenode_info.cc

@@ -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;