Skip to content

Commit

Permalink
fix bug for call timeout
Browse files Browse the repository at this point in the history
blocking call will block forever if connection of flora service broken.
  • Loading branch information
张晨 authored and 张晨 committed Apr 29, 2019
1 parent af02804 commit 17cce22
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ int32_t Client::call(const char *name, shared_ptr<Caps> &msg,
if (c <= 0)
return FLORA_CLI_EINVAL;

// timepoint of call timeout
// +200ms for socket data transfer cost time
auto tp = steady_clock::now() + milliseconds(timeout + 200);

unique_lock<mutex> locker(req_mutex);
PendingRequestList::iterator it =
pending_requests.emplace(pending_requests.end());
Expand All @@ -531,12 +535,16 @@ int32_t Client::call(const char *name, shared_ptr<Caps> &msg,
break;
}

if (connection.get() == nullptr) {
if (connection->closed()) {
retcode = close_reason;
goto exit;
}

req_reply_cond.wait(locker);
auto wr = req_reply_cond.wait_until(locker, tp);
if (wr == cv_status::timeout) {
retcode = FLORA_CLI_ETIMEOUT;
break;
}
}

exit:
Expand Down

0 comments on commit 17cce22

Please sign in to comment.