-
Notifications
You must be signed in to change notification settings - Fork 152
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
JSON-RPC 1.0 compliance bugs #658
Comments
The client is sending an empty message back? Do you mean the server is? The sample message you shared is a response message, so the RPC server would presumably be sending this back to the client that issued the request. I'll assume you just got the roles mixed up and that your observation is that a StreamJsonRpc server is sending the response back with Per the JSON-RPC spec, requests (that merit responses) have an
The spec has more to say about this, including discouraging use of
I believe then that the |
Yeah, just re-read my initial issue and realised what I was saying wasn't all that clear, I'd completely neglected to mention that I'm talking to a JSON-RPC 1.0 service. The issue I currently have is that my client is talking to a JSON-RPC 1.0 service; simply listening for notifications. However, as per JSON-RPC 1.0, the ID must be present, but null. This is slightly different to notifications in JSON-RPC 2.0 which state that the ID must not be present. What I've noticed is that the The issues I'm getting seem to be:
I've put a simple example my issue on GitHub here. Running both the client/server and shows the notifications being sent okay, just changing both versions to 1.0 and it'll fall over. |
@Daveycoder: 1.0 support certainly isn't top of our radar, so it's conceivable we have bugs in this area. Are you putting StreamJsonRpc into 1.0 mode by setting So for at least 2 of the 3 issues you list, we probably have legit bugs. I'm going to rename your issue to reflect that this is around JSON-RPC 1.0 support. |
@AArnott Thanks for the reply; yes, I'm setting the ProtocolVersion, and the title is now certainly more appropriate! Totally appreciate that 1.0 support isn't at the top of anyone's radar at the moment - unfortunately, some of us still have to deal with legacy systems :-( Thanks for your time. Cheers, Dave. |
We found a workaround by using custom message handler. public class MyWebSocketMessageHandler : WebSocketMessageHandler
{
public MyWebSocketMessageHandler(WebSocket webSocket) : base(webSocket)
{
}
public MyWebSocketMessageHandler(WebSocket webSocket, IJsonRpcMessageFormatter formatter, int sizeHint = 4096) : base(webSocket, formatter, sizeHint)
{
}
protected override async ValueTask<JsonRpcMessage?> ReadCoreAsync(CancellationToken cancellationToken)
{
JsonRpcMessage? rpcMessage = await base.ReadCoreAsync(cancellationToken);
if (rpcMessage is JsonRpcRequest request)
{
if ((request.RequestId.Number is null && request.RequestId.String is null) || request.RequestId.IsNull)
{
request.RequestId = RequestId.NotSpecified;
}
}
return rpcMessage;
}
} |
I've been getting several JSON errors on my server and have tracked them down to the client sending an empty message back; i.e.
This seems to be down to line 73 in the
RequestId
class which will always return a false; thethis.IsNull
in theRequestId(string? id)
ctor will always returntrue
if it is null (which is correct), but theIsEmpty
method (line 73) breaks this. Changing it frompublic bool IsEmpty => this.Number is null && this.String is null && !this.IsNull;
to
public bool IsEmpty => (this.Number is null && this.String is null) || this.IsNull;
seems to fix the issue (I'm not sure of the relevance of the other checks - IMHO the
RequestId
eitherIsNull
or not, but I'm very likely to be missing something as it's late at night and I've spent all day trying to work out why I was getting these messages!)The text was updated successfully, but these errors were encountered: