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/c43491d7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c43491d7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c43491d7

Branch: refs/heads/1.3.x
Commit: c43491d7aacce30a21cb1c034927099769e5e0f0
Parents: b0c6a31
Author: Greg Mann <g...@mesosphere.io>
Authored: Fri Mar 2 15:39:58 2018 -0800
Committer: Gilbert Song <songzihao1...@gmail.com>
Committed: Mon Mar 5 18:14:59 2018 -0800

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


http://git-wip-us.apache.org/repos/asf/mesos/blob/c43491d7/src/docker/docker.cpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp
index dfcfff8..9fefb9c 100755
--- a/src/docker/docker.cpp
+++ b/src/docker/docker.cpp
@@ -1101,6 +1101,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