Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/rpc/jsonrpc: client implementation is not compatible with JSON-RPC 1.0 spec #30188

Open
stefangluszek opened this issue Feb 12, 2019 · 7 comments
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@stefangluszek
Copy link

stefangluszek commented Feb 12, 2019

According to JSON-RPC 1.0 specification the params property should be an array of object. The canonical example of calling remote methods with JSON-RPC 1.0 is to send the parameters as one dimensional JSON array:
{"method": "concat", "params": ["foo", "bar"], "id": 123}
The GO's client implementation will always wrap the params property in an additional array:
{"method": "concat", "params": [["foo", "bar"]], "id": 123}
This works fine as long as both ends use the GO's implementation and expect the actual params to be the first element of the params array. It becomes a problem if you have another server implementation of JSON-RPC 1.0 but want to use GO's client to call remote methods.

I have worked around this issue locally by fixing it in my go fork.

@katiehockman katiehockman changed the title net/rpc/jsonrpc: Client implementation is not compatible with specification net/rpc/jsonrpc: client implementation is not compatible with JSON-RPC 1.0 spec Feb 12, 2019
@katiehockman
Copy link
Contributor

katiehockman commented Feb 12, 2019

/cc @robpike

@robpike
Copy link
Contributor

robpike commented Feb 12, 2019

I don't see how to fix this without breaking things. I don't see how to leave this alone without breaking things. Help wanted.

@katiehockman katiehockman added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Feb 12, 2019
@katiehockman katiehockman added this to the Go1.13 milestone Feb 12, 2019
@jamdagni86
Copy link
Contributor

jamdagni86 commented Mar 11, 2019

@stefangluszek are u sending a PR for this?

@stefangluszek
Copy link
Author

stefangluszek commented Mar 11, 2019

No because the fix is not backward compatible. It's still the right fix but it will break the existing clients and servers. You would either have to upgrade both client and the server with the fix or make changes to your client to explicitly wrap the param in an array before passing it to jsonrpc.Call. I am not sure what is the GO policy on backward compatibility.

@robpike
Copy link
Contributor

robpike commented Mar 11, 2019

The policy is we can't break things except under very special circumstances that I'm not convinced apply here.

https://golang.org/doc/go1compat

@alexus1024
Copy link

alexus1024 commented Mar 12, 2019

The usual way of fixing problems like that - is a switch "fixed_jsonrpc1_array_parameters_behaviour" :) in client struct. Defaulted to false value. With a plan to change default value to true in future.
Not a great solution, but solution. And it will not break backward compatibility.

@stefangluszek
Copy link
Author

stefangluszek commented Mar 12, 2019

Yes adding a feature flag to protect the change would work, not pretty though.

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants