Skip to content

Commit b3b26e1

Browse files
committed
rpc: fix -rpcclienttimeout 0 option
1 parent 561a7d3 commit b3b26e1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/bitcoin-cli.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,20 @@ static UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, co
316316

317317
// Synchronously look up hostname
318318
raii_evhttp_connection evcon = obtain_evhttp_connection_base(base.get(), host, port);
319-
evhttp_connection_set_timeout(evcon.get(), gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
319+
320+
// Set connection timeout
321+
{
322+
const int timeout = gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT);
323+
if (timeout > 0) {
324+
evhttp_connection_set_timeout(evcon.get(), timeout);
325+
} else {
326+
// Indefinite request timeouts are not possible in libevent-http, so we
327+
// set the timeout to a very long time period instead.
328+
329+
constexpr int YEAR_IN_SECONDS = 31556952; // Average length of year in Gregorian calendar
330+
evhttp_connection_set_timeout(evcon.get(), 5 * YEAR_IN_SECONDS);
331+
}
332+
}
320333

321334
HTTPReply response;
322335
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);

0 commit comments

Comments
 (0)