You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2019/08/13 14:55:00 UTC

[mesos] 02/02: Guarded access to possibly destructed resource provider driver.

This is an automated email from the ASF dual-hosted git repository.

bbannier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 6fb9b4a5c93378305bd54c8b1f5b12a79377318e
Author: Benjamin Bannier <bb...@apache.org>
AuthorDate: Tue Aug 13 11:05:35 2019 +0200

    Guarded access to possibly destructed resource provider driver.
    
    We provide a method to tear down a resource provider driver which
    internally resets the resource provider HTTP driver pointer. We need to
    prevent access to the pointed to value once the driver has been torn
    down.
    
    This patch switches all internal uses of the the driver to `send` data
    to use a public interface method instead. We also make sure that that
    public method does not access an invalidated pointed to value.
    
    Review: https://reviews.apache.org/r/71277
---
 src/tests/mesos.hpp | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 1b00881..25359a2 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -3136,7 +3136,11 @@ public:
 
   process::Future<Nothing> send(const Call& call)
   {
-    return driver->send(call);
+    if (driver != nullptr) {
+      return driver->send(call);
+    } else {
+      return process::Failure("Cannot send call since driver is torn down");
+    }
   }
 
   void start(
@@ -3198,7 +3202,10 @@ public:
     call.set_type(Call::SUBSCRIBE);
     call.mutable_subscribe()->mutable_resource_provider_info()->CopyFrom(info);
 
-    driver->send(call);
+    send(call)
+      .onFailed([](const std::string& failure) {
+        LOG(INFO) << "Failed to send call: " << failure;
+      });
   }
 
   void subscribedDefault(const typename Event::Subscribed& subscribed)
@@ -3224,7 +3231,10 @@ public:
       update->mutable_resource_version_uuid()->set_value(
           id::UUID::random().toBytes());
 
-      driver->send(call);
+      send(call)
+        .onFailed([](const std::string& failure) {
+          LOG(INFO) << "Failed to send call: " << failure;
+        });
     }
   }
 
@@ -3299,7 +3309,10 @@ public:
 
     update->mutable_latest_status()->CopyFrom(update->status());
 
-    driver->send(call);
+    send(call)
+      .onFailed([](const std::string& failure) {
+        LOG(INFO) << "Failed to send call: " << failure;
+      });
   }
 
   void publishDefault(const typename Event::PublishResources& publish)
@@ -3315,7 +3328,10 @@ public:
     update->mutable_uuid()->CopyFrom(publish.uuid());
     update->set_status(Call::UpdatePublishResourcesStatus::OK);
 
-    driver->send(call);
+    send(call)
+      .onFailed([](const std::string& failure) {
+        LOG(INFO) << "Failed to send call: " << failure;
+      });
   }
 
   void teardownDefault() {}