Sporadically receiving connection error when doing JSON RPC requests

+2 votes

I made a web application which sends JSON RPC requests to a multichain node on the same server (localhost), the requests work correctly most of the time, except that in about 4% of the cases the request fails and the only error I have available is what the standard .net webrequest library tells me:  "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." which should mean that for some reason multichain is closing down the connection while in the process of sending back a response.

I've been trying to debug this for a while without success, it may happen with any JSON RPC request and generally happens when there a bunch of requests in a short time (right now I'm doing tests with 1 second delay and it happens around the tenth consecutive request).

I don't know what's happening and how to debug it since it seems to be a problem on the side of multichain and one that happens only a small percentage of the time.

I tested on multichain community 2.0.3 but I had this happen even on 2.0.2.

What can I do to further investigate this situation?
Any idea on why it could be happening?
asked Oct 23, 2019 by mgiacomellijsb

1 Answer

0 votes

If the problem is occurring when you are sending a lot of requests at the same time, the likely explanation is that some of these requests are taking a while, and your MultiChain node is not able to answer some new incoming connections because all the RPC threads are used up. Three suggestions that might help:

  • Improve the performance of the server (maybe this is a light cloud instance?)
  • Use the rpcthreads runtime parameter to increase the number of RPC commands that can be in process in parallel.
  • Increase the timeout parameters on the client side.
answered Oct 26, 2019 by MultiChain
Just to add, what I am observing from the debug log after adding -debug=mcapi flag is the client encountered the error and MultiChain did not receive any input from the client. @mgiacomellijsb can you verify if that's the same for your case?

@mgiacomellijsb, I've also changed the .net webrequest to HttpClient but still faced with the same issue. Let me know your findings for restsharp.
Hey all, after a long time I managed to find time to do some more tests and the theory was right: 200 consecutive requests directly to multichain through postman work without a hitch, the same can't be said for the same amount of requests done through the .NET webrequest library.
Now I'll try to switch up to another library and see if it's what's causing the issues
@mgiacomellijsb Will be looking forward to your findings. Thanks.
I can't believe it but I managed to solve the issue (apparently) once and for all and I didn't even do anything.
Basically on the lucidocean github there was an open pull request that fixed the issue https://github.com/LucidOcean/multichain/pull/31

it was a weird timeout lease thing, I just did a stress test with over 400 consecutive calls in a very short timespan and they all went through correctly.
Multichain is not bugged, it's just the lucidocean that did the web request poorly and if you apply that patch it will be solved
Excellent findings! Thanks.