Skip to content

Commit 3530d5d

Browse files
author
MarcoFalke
committed
Merge #18335: bitcoin-cli: print useful error if bitcoind rpc work queue exceeded
8dd5946 add functional test (Larry Ruane) b5a80fa util: Handle HTTP_SERVICE_UNAVAILABLE in bitcoin-cli (Hennadii Stepanov) Pull request description: If `bitcoind` is processing 16 RPC requests, attempting to submit another request using `bitcoin-cli` produces this less-than-helpful error message: `error: couldn't parse reply from server`. This PR changes the error to: `error: server response: Work queue depth exceeded`. ACKs for top commit: fjahr: tACK 8dd5946 luke-jr: utACK 8dd5946 (no changes since previous utACK) hebasto: re-ACK 8dd5946, only suggested changes since my [previous](bitcoin/bitcoin#18335 (review)) review. darosior: ACK 8dd5946 Tree-SHA512: 33e25f6ff05d9b56fae2bdb68b132557bb8e995f5438ac4fbbc53c304c5152a98aa43c43600c31d8a6a2830cbd48bf8ec7d89dce50190b29ec00a43830126913
2 parents 18cd088 + 8dd5946 commit 3530d5d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/bitcoin-cli.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
708708
} else {
709709
throw std::runtime_error("Authorization failed: Incorrect rpcuser or rpcpassword");
710710
}
711+
} else if (response.status == HTTP_SERVICE_UNAVAILABLE) {
712+
throw std::runtime_error(strprintf("Server response: %s", response.body));
711713
} else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR)
712714
throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
713715
else if (response.body.empty())

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
262262
item.release(); /* if true, queue took ownership */
263263
else {
264264
LogPrintf("WARNING: request rejected because http work queue depth exceeded, it can be increased with the -rpcworkqueue= setting\n");
265-
item->req->WriteReply(HTTP_INTERNAL_SERVER_ERROR, "Work queue depth exceeded");
265+
item->req->WriteReply(HTTP_SERVICE_UNAVAILABLE, "Work queue depth exceeded");
266266
}
267267
} else {
268268
hreq->WriteReply(HTTP_NOT_FOUND);

test/functional/interface_rpc.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from test_framework.authproxy import JSONRPCException
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import assert_equal, assert_greater_than_or_equal
11+
from threading import Thread
12+
import subprocess
13+
1114

1215
def expect_http_status(expected_http_status, expected_rpc_code,
1316
fcn, *args):
@@ -18,6 +21,16 @@ def expect_http_status(expected_http_status, expected_rpc_code,
1821
assert_equal(exc.error["code"], expected_rpc_code)
1922
assert_equal(exc.http_status, expected_http_status)
2023

24+
25+
def test_work_queue_getblock(node, got_exceeded_error):
26+
while not got_exceeded_error:
27+
try:
28+
node.cli('getrpcinfo').send_cli()
29+
except subprocess.CalledProcessError as e:
30+
assert_equal(e.output, 'error: Server response: Work queue depth exceeded\n')
31+
got_exceeded_error.append(True)
32+
33+
2134
class RPCInterfaceTest(BitcoinTestFramework):
2235
def set_test_params(self):
2336
self.num_nodes = 1
@@ -67,10 +80,23 @@ def test_http_status_codes(self):
6780
expect_http_status(404, -32601, self.nodes[0].invalidmethod)
6881
expect_http_status(500, -8, self.nodes[0].getblockhash, 42)
6982

83+
def test_work_queue_exceeded(self):
84+
self.log.info("Testing work queue exceeded...")
85+
self.restart_node(0, ['-rpcworkqueue=1', '-rpcthreads=1'])
86+
got_exceeded_error = []
87+
threads = []
88+
for _ in range(3):
89+
t = Thread(target=test_work_queue_getblock, args=(self.nodes[0], got_exceeded_error))
90+
t.start()
91+
threads.append(t)
92+
for t in threads:
93+
t.join()
94+
7095
def run_test(self):
7196
self.test_getrpcinfo()
7297
self.test_batch_request()
7398
self.test_http_status_codes()
99+
self.test_work_queue_exceeded()
74100

75101

76102
if __name__ == '__main__':

0 commit comments

Comments
 (0)