aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2019-10-14 00:19:47 +0200
committerfanquake <fanquake@gmail.com>2019-10-19 14:03:48 -0400
commite1bacb591a75375461cdf9e39e4dda4acdbd6981 (patch)
treeed8aeb7963f4f13f23c763d1dac5a324281367ca /src
parent6a45766acbf4fc8d2ce8ab3e1eb1afc85a7c05ca (diff)
rpc: fix -rpcclienttimeout 0 option
Github-Pull: #17131 Rebased-From: b3b26e149c34fee9c7ae8548c6e547ec6254b441
Diffstat (limited to 'src')
-rw-r--r--src/bitcoin-cli.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index a6756fcce7..7fdd8e9466 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -314,7 +314,20 @@ static UniValue CallRPC(BaseRequestHandler *rh, const std::string& strMethod, co
// Synchronously look up hostname
raii_evhttp_connection evcon = obtain_evhttp_connection_base(base.get(), host, port);
- evhttp_connection_set_timeout(evcon.get(), gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
+
+ // Set connection timeout
+ {
+ const int timeout = gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT);
+ if (timeout > 0) {
+ evhttp_connection_set_timeout(evcon.get(), timeout);
+ } else {
+ // Indefinite request timeouts are not possible in libevent-http, so we
+ // set the timeout to a very long time period instead.
+
+ constexpr int YEAR_IN_SECONDS = 31556952; // Average length of year in Gregorian calendar
+ evhttp_connection_set_timeout(evcon.get(), 5 * YEAR_IN_SECONDS);
+ }
+ }
HTTPReply response;
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);