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/d841ba45 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d841ba45 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d841ba45 Branch: refs/heads/1.4.x Commit: d841ba457926baaec6c188ec0f08a95d295af5ab Parents: 155b3af Author: Greg Mann <[email protected]> Authored: Fri Mar 2 15:39:58 2018 -0800 Committer: Gilbert Song <[email protected]> Committed: Mon Mar 5 18:11:12 2018 -0800 ---------------------------------------------------------------------- src/docker/docker.cpp | 7 +++++++ 1 file changed, 7 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/d841ba45/src/docker/docker.cpp ---------------------------------------------------------------------- diff --git a/src/docker/docker.cpp b/src/docker/docker.cpp index e9e600e..2a9316d 100755 --- a/src/docker/docker.cpp +++ b/src/docker/docker.cpp @@ -1273,6 +1273,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);
