scoin / multichain-node

A simple wrapper for Multichain's JSON RPC api that parses your input.
MIT License
73 stars 54 forks source link

Set timeout for a command #23

Open amolpednekar opened 6 years ago

amolpednekar commented 6 years ago

I am running benchmark tests for multichain, and using this library to do publish stream actions. When I increase the send rate to something like 100 transactions per second ( multichainObject.publish command ), I start getting Error: connect ETIMEDOUT or Error: read ECONNRESET .

Is there a way to set a timeout for a command, or do I need to explicitly encapsulate this publish call in a setTimeout function? What is the correct approach here?

flaviostutz commented 6 years ago

I need this thing too!

flaviostutz commented 6 years ago

@amolpednekar, you can try our fork until scoin accepts the PR:

replace the dependency in your package.json by: "multichain-node": "git://github.com/labbsr0x/multichain-node.git#development",

Add the 'timeout' attribute to the connection object. Something like: this.multichainNode = MultichainNode({ port: port, host: host, user: user, pass: pass, timeout: 5000 });

Please tell me if that doesn't work.

amolpednekar commented 6 years ago

@flaviostutz The timeout issue in my case turned out to be because CPU on the VM on which my peer was running, was maxxing out, so the peer was dropping the rpc connection.

I was able to test the same with my own timeouts by setting req.setTimeout(2000, callback()) in lib/client.js after line #41.

You may want to consider using async.series to send the next request only after the previous has been completed. (Not applicable in my case as I need to load test for a benchmark, so I want to see at what point it breaks anyway).

Edit: I tried your fork, works fine. The req.on('error') event is triggered in any case since you're calling req.abort() on socket timeout, so it ends up in the same place, but yes, can add some handlers in the socket timeout event.