aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2019-10-16 16:00:39 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2019-10-16 16:00:49 +0200
commit5a3dd93594551efdc4059126b061b8c751ec3f29 (patch)
tree108203b4af6f3acc3d28fd7d4265cdd69d1fa9e9 /src
parent1f6638630ef8e196e9a7dd6a3e417c186e2cc7b9 (diff)
parentb3b26e149c34fee9c7ae8548c6e547ec6254b441 (diff)
Merge #17131: rpc: fix -rpcclienttimeout 0 option
b3b26e149c34fee9c7ae8548c6e547ec6254b441 rpc: fix -rpcclienttimeout 0 option (Fabian Jahr) Pull request description: fixes #17117 I understood the bug as the help string being wrong, rather than that this feature is missing and should be added. Let me know if it should be the other way around. It is notable that if 0 is given as an argument, the fallback that is being used is the libevent default of 50 seconds, rather than `DEFAULT_HTTP_CLIENT_TIMEOUT` (900 seconds). This is not intuitive for the user. I could handle this in this PR but I am unsure which would be the better solution then: Actually adding the feature as described in the help string or falling back to `DEFAULT_HTTP_CLIENT_TIMEOUT`? Happy to hear opinions. ACKs for top commit: MarcoFalke: unsigned ACK b3b26e149c34fee9c7ae8548c6e547ec6254b441 Tree-SHA512: 65e526a652c0adcdb4f895e8d78d60c7caa5904c9915b165a3ae95725c87d13af1f916359f80302452a2fcac1a80f4c58cd805ec8c28720fa4b91b3c8baa4155
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 73773c4ec5..71b40dca16 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -316,7 +316,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);