Skip to content

Commit 2190ea6

Browse files
committed
rpc: Split option -rpctimeout into -rpcservertimeout and -rpcclienttimeout
The two timeouts for the server and client, are essentially different: - In the case of the server it should be a lower value to avoid clients clogging up connection slots - In the case of the client it should be a high value to accomedate slow responses from the server, for example for slow queries or when the lock is contended Split the options into `-rpcservertimeout` and `-rpcclienttimeout` with respective defaults of 30 and 900.
1 parent 8b2d6ed commit 2190ea6

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

contrib/debian/examples/bitcoin.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
# How many seconds bitcoin will wait for a complete RPC HTTP request.
7575
# after the HTTP connection is established.
76-
#rpctimeout=30
76+
#rpcclienttimeout=30
7777

7878
# By default, only RPC connections from localhost are allowed.
7979
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,

src/bitcoin-cli.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
using namespace std;
2424

25+
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
26+
2527
std::string HelpMessageCli()
2628
{
2729
string strUsage;
@@ -37,6 +39,7 @@ std::string HelpMessageCli()
3739
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
3840
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
3941
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
42+
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout during HTTP requests (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
4043

4144
return strUsage;
4245
}
@@ -150,7 +153,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
150153
struct evhttp_connection *evcon = evhttp_connection_base_new(base, NULL, host.c_str(), port); // TODO RAII
151154
if (evcon == NULL)
152155
throw runtime_error("create connection failed");
153-
evhttp_connection_set_timeout(evcon, GetArg("-rpctimeout", 30));
156+
evhttp_connection_set_timeout(evcon, GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
154157

155158
HTTPReply response;
156159
struct evhttp_request *req = evhttp_request_new(http_request_done, (void*)&response); // TODO RAII

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ bool InitHTTPServer()
374374
return false;
375375
}
376376

377-
evhttp_set_timeout(http, GetArg("-rpctimeout", DEFAULT_HTTP_TIMEOUT));
377+
evhttp_set_timeout(http, GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
378378
evhttp_set_max_body_size(http, MAX_SIZE);
379379
evhttp_set_gencb(http, http_request_cb, NULL);
380380

src/httpserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static const int DEFAULT_HTTP_THREADS=4;
1515
static const int DEFAULT_HTTP_WORKQUEUE=16;
16-
static const int DEFAULT_HTTP_TIMEOUT=30;
16+
static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
1717

1818
struct evhttp_request;
1919
struct event_base;

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ std::string HelpMessage(HelpMessageMode mode)
440440
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
441441
if (showDebug) {
442442
strUsage += HelpMessageOpt("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE));
443-
strUsage += HelpMessageOpt("-rpctimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_TIMEOUT));
443+
strUsage += HelpMessageOpt("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT));
444444
}
445445

446446
if (mode == HMM_BITCOIN_QT)

0 commit comments

Comments
 (0)