From 606d20c6c0678be0cc7d0163defceacd1ffe03ae Mon Sep 17 00:00:00 2001 From: James Date: Wed, 22 Feb 2017 12:12:24 -0500 Subject: [PATCH] HDFS-11436: libhdfs++: Fix race condition in ScopedResolver. Contributed by James Clampffer. --- .../src/main/native/libhdfspp/lib/common/namenode_info.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/namenode_info.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/namenode_info.cc index bd430915525..bd3f44fdeac 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/namenode_info.cc +++ b/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 result_status_ = std::make_shared>(); + std::shared_ptr> 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;