Just waiting 3 seconds when stop container.

If container manager dies before session manager dying,
the session manager cannot exit if it waits for all.

This patch fix the above issue.

Signed-off-by: Han Pengfei <hanpfei@gmail.com>
This commit is contained in:
Han Pengfei 2018-02-01 15:00:23 +08:00
commit 15803e1868
3 changed files with 9 additions and 4 deletions

View file

@ -24,6 +24,9 @@
namespace anbox {
namespace container {
const std::chrono::milliseconds ManagementApiStub::stop_waiting_timeout{3000};
ManagementApiStub::ManagementApiStub(
const std::shared_ptr<rpc::Channel> &channel)
: channel_(channel) {}
@ -75,7 +78,9 @@ void ManagementApiStub::stop_container() {
channel_->call_method("stop_container", &message, c->response.get(),
google::protobuf::NewCallback(this, &ManagementApiStub::container_stopped, c.get()));
c->wh.wait_for_all();
// If container manager dies before session manager, the session manager
// cannot exit if it waits for all, so just wait for 3 seconds.
c->wh.wait_for_pending(stop_waiting_timeout);
if (c->response->has_error()) throw std::runtime_error(c->response->error());
}

View file

@ -56,6 +56,7 @@ class ManagementApiStub : public DoNotCopyOrMove {
mutable std::mutex mutex_;
std::shared_ptr<rpc::Channel> channel_;
static const std::chrono::milliseconds stop_waiting_timeout;
};
} // namespace container
} // namespace anbox

View file

@ -72,11 +72,10 @@ void AdbMessageProcessor::advance_state() {
// one is established but will not use it until the active one is closed.
lock_.lock();
if (state_ == closed_by_host) {
if (state_ == closed_by_host)
host_connector_.reset();
} else {
else
wait_for_host_connection();
}
lock_.unlock();
break;