Skip to content

Expand/restrict types per the JSON-RPC spec#631

Merged
dbaeumer merged 1 commit intomicrosoft:masterfrom
AArnott:conformance
Jun 11, 2020
Merged

Expand/restrict types per the JSON-RPC spec#631
dbaeumer merged 1 commit intomicrosoft:masterfrom
AArnott:conformance

Conversation

@AArnott
Copy link
Member

@AArnott AArnott commented Jun 10, 2020

The id and params fields of a JSON-RPC request were not typed consistently with the JSON-RPC spec for request objects.

In particular:

  1. id may be null (although such would be quite bizarre)
  2. params must be omitted (i.e. not null) or an array or an object. It may not be a number or a string.

* The request id.
*/
id: number | string;
id: number | string | null;
Copy link
Member

@dbaeumer dbaeumer Jun 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is correct from a spec point but it will cause trouble to correlate the response to the promise if two requests are sent with the id set to null. @AArnott how do you handle this? I would like to not allow this because I can't guarantee correctness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StreamJsonRpc has had to interop with other JSON-RPC implementations that actually used null as the value for an explicitly specified id. Those other parties were buggy though, for related reasons. But we did build up some resilience to it to deal with it a bit better.
I think it's bonkers that the spec allows null, which I guess should be treated as a unique value just like any other number or string that might be used as an id. Perhaps if some implementation never sent two requests concurrently, they could just use id: null for every single request.
I wouldn't worry about correlating a response to the request if I were you. On the server side, you don't have to use the id to correlate anyway. And if you're on the client side, you get to decide what the ID is, so you can simply avoid ever using null as a request ID.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more for me to avoid that I ever create a request with a id being null. Since the library doesn't allow sending requests directly it will not cause harm. But I with change the code for createRequestQueueKey and throw if I receive a message with id null.

@dbaeumer dbaeumer merged commit 2edc6f8 into microsoft:master Jun 11, 2020
@AArnott AArnott deleted the conformance branch June 12, 2020 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants