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

Comments

Projects
None yet
5 participants
@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

This comment has been minimized.

Copy link
Contributor

katiehockman commented Feb 12, 2019

/cc @robpike

@robpike

This comment has been minimized.

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.

@jamdagni86

This comment has been minimized.

Copy link
Contributor

jamdagni86 commented Mar 11, 2019

@stefangluszek are u sending a PR for this?

@stefangluszek

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Author

stefangluszek commented Mar 12, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.