From 8237c963ed0f10d3e00ec277d46a74722424e3b0 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Thu, 24 Aug 2017 08:26:52 +0200 Subject: [PATCH] bridge: use five second timeout for all RPC Before we were waiting forever for a reply which never occured in some cases due to errors when processing incoming protobuf messages we now abort the RPC call after a timeout of five seconds to keep operational. --- src/anbox/bridge/android_api_stub.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/anbox/bridge/android_api_stub.cpp b/src/anbox/bridge/android_api_stub.cpp index 4762b15..e08eb30 100644 --- a/src/anbox/bridge/android_api_stub.cpp +++ b/src/anbox/bridge/android_api_stub.cpp @@ -29,6 +29,10 @@ namespace fs = boost::filesystem; +namespace { +constexpr const std::chrono::milliseconds default_rpc_call_timeout{5000}; +} // namespace + namespace anbox { namespace bridge { AndroidApiStub::AndroidApiStub() {} @@ -103,7 +107,9 @@ void AndroidApiStub::launch(const android::Intent &intent, google::protobuf::NewCallback(this, &AndroidApiStub::application_launched, c.get())); - launch_wait_handle_.wait_for_all(); + launch_wait_handle_.wait_for_pending(default_rpc_call_timeout); + if (!launch_wait_handle_.has_result()) + throw std::runtime_error("RPC call timed out"); if (c->response->has_error()) throw std::runtime_error(c->response->error()); } @@ -135,7 +141,9 @@ void AndroidApiStub::set_focused_task(const std::int32_t &id) { google::protobuf::NewCallback( this, &AndroidApiStub::focused_task_set, c.get())); - set_focused_task_handle_.wait_for_all(); + set_focused_task_handle_.wait_for_pending(default_rpc_call_timeout); + if (!set_focused_task_handle_.has_result()) + throw std::runtime_error("RPC call timed out"); if (c->response->has_error()) throw std::runtime_error(c->response->error()); } @@ -162,7 +170,9 @@ void AndroidApiStub::remove_task(const std::int32_t &id) { google::protobuf::NewCallback( this, &AndroidApiStub::task_removed, c.get())); - remove_task_handle_.wait_for_all(); + remove_task_handle_.wait_for_pending(default_rpc_call_timeout); + if (!remove_task_handle_.has_result()) + throw std::runtime_error("RPC call timed out"); if (c->response->has_error()) throw std::runtime_error(c->response->error()); } @@ -198,7 +208,9 @@ void AndroidApiStub::resize_task(const std::int32_t &id, google::protobuf::NewCallback( this, &AndroidApiStub::task_resized, c.get())); - resize_task_handle_.wait_for_all(); + resize_task_handle_.wait_for_pending(default_rpc_call_timeout); + if (!resize_task_handle_.has_result()) + throw std::runtime_error("RPC call timed out"); if (c->response->has_error()) throw std::runtime_error(c->response->error()); }