jsonrpcpp icon indicating copy to clipboard operation
jsonrpcpp copied to clipboard

Threadsafety of Parser::parse() and client side support for response callbacks

Open HuskerC opened this issue 6 years ago • 3 comments

Hello,

great job so far with your jsonrpcpp. It's easy to use. One thing that came to me while using it was, that trying to use it with a server with lots of parallel jsonrpc calls, the parser callbacks cannot be used in a multi-threaded environment because they lack synchronisation with the manipulation of the callback container. So if the callback library is changing, while there is heavy load on the line, this could cause some unexpected behaviour. Would be nice, if you might integrate this in a future release.

A second thing that would be nice to have is a callback wrapper for responses on the client side, to support asynchronous call handling.

I wrapped both of those things arround from outside so far.

If you need any assistance I'd be glad to help with a fork.

Best regards and keep going.

HuskerC avatar Dec 14 '17 18:12 HuskerC

Hi @HuskerC

sure you can do a fork! As fas as I understand, the problem can be solved by protecting the xxx_callback_ containers with a lock guard. What is your second thing? Do you want to call the callback functions from a thread? If you have lots of responses, you should limit the number of threads (i.e. not spawn detached threads) and introduce a queue and a thread pool. Maybe that's what you mean with "wrapper", to have this optional outside the lib.

badaix avatar Jan 04 '18 11:01 badaix

Yeah, the lock guard is what I considererd as well. My second issue is regarding the client side use of your library. You have callbacks in your code, to implement some kind of request queue on server side. Would be nice if the same mechanism would exist for the client side use with a response queue. So that you can place response handlers on the client side to handle async responses for the client’s requests.

Best regards and happy new year.

HuskerC avatar Jan 04 '18 11:01 HuskerC

Hi!

Regarding this issue, can this library be safely used in a multi-threaded application?

ferreteleco avatar Apr 24 '20 19:04 ferreteleco