iris-connect / eps

Our endpoint system (eps) that manages and secures the communication between different actors in the IRIS connect ecosystem. Think of it as a distributed service mesh router as well as a decentralized message broker. Still evolving, use with caution.
https://iris-connect.github.io/eps/docs/
GNU Affero General Public License v3.0
12 stars 2 forks source link

ID must be a string or the JSON RPC call fails #2

Closed bitboxer closed 3 years ago

bitboxer commented 3 years ago

I tried to send the demo message with my ruby code, but sadly the payload does not work if the JSON contains a number for the id:

{
  "jsonrpc": "2.0",
  "method": "ls-1.lookup",
  "params": {
    "name": "Ginos"
  },
  "id": 232536406201
}

The spec defines the ID as MUST contain a String, Number, or NULL so this might be a bug?

adewes commented 3 years ago

Hi @bitboxer, yes we should mention that. Technically JSON-RPC can also accept numbers as IDs but since we use the IDs for routing messages and internally convert them into strings of the form [operator].[service](id) we don't allow that. We could of course implement conversion but that might cause surprising behavior (e.g. you pass in an ID that could be a number but is passed as a string, and we convert it to a number when passing it back).

We also don't allow NULL values as we need the IDs for routing and as asynchronous requests wouldn't be identifiable otherwise.

bitboxer commented 3 years ago

Hm, that might not be possible to change depending on what library the clients use. I already have a fork of an outdated gem to make it work with latest Rails, for me it's not a problem to add that behavior to it. Others might not be so "lucky" 😀.

adewes commented 3 years ago

Ok, I understand. I'll think about how we can make this work.

adewes commented 3 years ago

So I think we can implictly convert numbers to strings (though as I said this might cause unexpected behavior in some cases) and auto-generate IDs for requests that don't include one. This'll be in the next release today or tomorrow.

adewes commented 3 years ago

Hey @bitboxer, so we've added support for numerical and null IDs to the JSON-RPC endpoint.

We will convert numerical IDs, annotate them and and convert them back automatically, so you shouldn't notice a difference. Edge cases (i.e. string IDs that match our custom number encoding format) should also be handled correctly. Requests with a null ID will get assigned a random 16-byte ID which you need to store in case you need to track the request.

If the problem persists please reopen this ticket.

adewes commented 3 years ago

Please note that Golang represents numerical IDs as float64 objects in JSON, so for very large IDs (e.g. 2444444444444444444) the back-and-forth conversion will yield incorrect values. We advise against using long integer IDs in requests for that reason.

bitboxer commented 3 years ago

Okay, will add a setting to make IDs strings in the library I am using.