Allow a larger timeout for rpc connect in bts api

This commit is contained in:
Eric Harding committed 2019-08-29 13:17:57 -04:00
1 parent f7b5eeb04c
commit d12200e977
2 files changed
+24 -6

No files matched your search

+21 -6
View File
@@ -140,14 +140,23 @@ void reply_error(ApiError error, raw_response_callback cb, void* extra) {
}
CAPI void api_client_send(ApiClient* pclient, const char* buffer, int buffer_length, raw_response_callback cb, void* extra) {
int32_t rpc_connect_timeout_ms() {
static int32_t t = config::get<config::RPCConfig>().rpc_connect_timeout_seconds() * 1000;
return t;
}
void api_client_send_internal(ApiClient* pclient, qbus::RPCRequest&& request, raw_response_callback cb, int32_t accumulated_delay, void* extra) {
bts_assert(pclient);
std::string strbuf(buffer, buffer_length);
qbus::RPCRequest request(move(strbuf));
pclient->rpc.wait_until_connected(1);
LOG(Api,Diag,"send rpc {}",((int64_t)buffer));
bool connected = pclient->rpc.wait_until_connected(0); //accumulated_delay ? 0 : 1);
if (!connected && accumulated_delay < rpc_connect_timeout_ms()) {
// This branch is the uncommon 'slow path' where connection is taking longer than we expect
LOG(Api,Diag,"rpc call delay waiting for connection {}",((int64_t)request.value().c_str()));
pclient->qbus.post([=, request{std::move(request)}]() mutable {
api_client_send_internal(pclient, std::move(request), cb, accumulated_delay + 100, extra);
}, 100);
return;
}
pclient->rpc.send(std::move(request), [=](qbus::RPCError e, const qbus::RPCReplyPtr& reply) {
LOG(Api,Diag,"rpc reply {}",((int64_t)buffer));
LOG(Api,Diag,"rpc reply {}",((int64_t)request.value().c_str()));
switch (e) {
case qbus::RPCError::RPC_OK:
safe_call_fn([&]() {
@@ -165,6 +174,12 @@ CAPI void api_client_send(ApiClient* pclient, const char* buffer, int buffer_len
}
});
}
CAPI void api_client_send(ApiClient* pclient, const char* buffer, int buffer_length, raw_response_callback cb, void* extra) {
LOG(Api,Diag,"send rpc {}",((int64_t)buffer));
std::string strbuf(buffer, buffer_length);
qbus::RPCRequest request(move(strbuf));
api_client_send_internal(pclient, std::move(request), cb, 0, extra);
}
CAPI bool api_client_is_on_qb_thread(ApiClient* pclient) {
return pclient->qbus.on_qb_thread();