Closed AndreiPashkin closed 3 years ago
Using a generator is a great suggestion. The default could replace the current implementation just incrementing a counter. The default generator can then be replaced by your own generating uuids for example.
I could make a PR with JSONRPCProtocol
class updated with option to provide custom ID generator.
Please do! But consider this:
1-2: to prevent breaking changes 3: to discourage swapping generators mid-flight (only for those who know what they're doing)
@lnoor, I now see a problem. JSONRPCProtocol
class doesn't verify response IDs:
https://github.com/mbr/tinyrpc/blob/fb7490ef098d3ec42cb756ae97887300ddbccc65/tinyrpc/protocols/jsonrpc.py#L572
Theoretically it should reject responses with unexpected IDs.
There is a private method
JSONRPCProtocol._get_unique_id()
that is responsible for generating unique IDs for RPC client requests: https://github.com/mbr/tinyrpc/blob/2b2857d1947e7019bb01e50badc801194684226b/tinyrpc/protocols/jsonrpc.py#L476It generates ID's by addition which may lead to a memory leak in case if client stays alive for a long time (month? year?). I believe some kind of sliding-window algorithm should be used there instead.