Skip to content

Commit 5a3dd93

Browse files
committed
Merge #17131: rpc: fix -rpcclienttimeout 0 option
b3b26e1 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 b3b26e1 Tree-SHA512: 65e526a652c0adcdb4f895e8d78d60c7caa5904c9915b165a3ae95725c87d13af1f916359f80302452a2fcac1a80f4c58cd805ec8c28720fa4b91b3c8baa4155
2 parents 1f66386 + b3b26e1 commit 5a3dd93

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)