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/d323bbd0 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d323bbd0 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d323bbd0 Branch: refs/heads/1.5.x Commit: d323bbd0836d7f8055d54cee699d4ecfdefb734e Parents: e72def4 Author: Greg Mann <g...@mesosphere.io> Authored: Fri Mar 2 15:39:58 2018 -0800 Committer: Gilbert Song <songzihao1...@gmail.com> Committed: Wed Mar 7 01:08:12 2018 -0800 ---------------------------------------------------------------------- src/docker/docker.cpp | 7 +++++++ 1 file changed, 7 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/d323bbd0/src/docker/docker.cpp ---------------------------------------------------------------------- diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp index 3e3b8d5..1daa13f 100644 --- a/src/docker/docker.cpp +++ b/src/docker/docker.cpp @@ -1293,6 +1293,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);