It does seem wrong that my proposed fix retains the practice of trying to decode a non-JSON string as JSON, and depending on that to fail. Yes, perhaps this is a bug in the server – should it be returning JSON in body
here rather than a plain string? But as I said at the end of the comment above, I was hesitant to change the server because I’m worried that there may be other RPC clients besides bitcoin-cli
that depend on the current (plain string) response. What do you think? If the fix is better in the server, I can do that.
Just for further information, the response returned in this work queue depth exceeded is (status 500 is HTTP_INTERNAL_SERVER_ERROR
):
0(gdb) f 0
1Breakpoint 1, CallRPC (rh=0x555555845e90, strMethod="getblockhash", args=std::vector of length 1, capacity 2 = {...})
2 at bitcoin-cli.cpp:406
3406 if (!valReply.read(response.body))
4(gdb) p response
5$2 = {
6 status = 500,
7 error = -1,
8 body = "Work queue depth exceeded"
9}
10(gdb)
Here’s a successful reply:
0(gdb) p response
1$6 = {
2 status = 200,
3 error = -1,
4 body = "{\"result\":\"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f\",\"error\":null,\"id\":1}\n"
5}
Here’s the response when requesting a nonsense method:
0(gdb) p response
1$2 = {
2 status = 404,
3 error = -1,
4 body = "{\"result\":null,\"error\":{\"code\":-32601,\"message\":\"Method not found\"},\"id\":1}\n"
5}
As part of this PR, I could also systematically search for and fix any other places where body
is returned as plain string (not JSON); so far I see only one:
0req->WriteReply(HTTP_BAD_METHOD, "JSONRPC server handles only POST requests")