badaix / jsonrpcpp

C++ JSON-RPC 2.0 library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

HuskerC opened this issue · 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.

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.

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.

Hi!

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