Avoided orphan subprocess in the Docker library.

This patch ensures that `Docker::inspect` will not leave orphan
subprocesses behind.

Review: https://reviews.apache.org/r/65887/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8346ab0c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8346ab0c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8346ab0c

Branch: refs/heads/master
Commit: 8346ab0c812559ef73e1bbd30718f6c74a023079
Parents: b0a2696
Author: Greg Mann <g...@mesosphere.io>
Authored: Fri Mar 2 15:39:58 2018 -0800
Committer: Gilbert Song <songzihao1...@gmail.com>
Committed: Fri Mar 2 15:40:30 2018 -0800

----------------------------------------------------------------------
 src/docker/docker.cpp | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8346ab0c/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index 9dd4ceb..bb81c4d 100644
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -1324,6 +1324,13 @@ void Docker::_inspect(
   // Set the `onDiscard` callback which will clean up the subprocess if the
   // caller discards the `Future` that we returned.
   synchronized (callback->second) {
+    // It's possible that the caller has discarded their future while we were
+    // creating a new subprocess, so we clean up here if necessary.
+    if (promise->future().hasDiscard()) {
+      commandDiscarded(s.get(), cmd);
+      return;
+    }
+
     callback->first = [promise, s, cmd]() {
       promise->discard();
       CHECK_SOME(s);

Reply via email to