rsocket / rsocket-net

.NET implementation of RSocket
Apache License 2.0
252 stars 42 forks source link

RequestStream messages are truncated usually after the 1st message frame #24

Open rupweb opened 3 years ago

rupweb commented 3 years ago

Per this SO for a net client (with either binary or string data encoding) the 1st message is received and treated properly and usually the 2nd but from then on messages are truncated. This causes a crash at RSocketProtocol.Handler.cs where the header type is unknown and therefore not handled.

To replicate the error start a Java spring boot RSocket server. Then spin up a net client with code like this:

var client = new RSocketClient(new WebSocketTransport("ws://127.0.0.1:7000/"));

Console.WriteLine("Connect Async");
await client.ConnectAsync(new RSocketOptions()
{ 
  DataMimeType = "application/json",
  MetadataMimeType = "message/x.rsocket.routing.v0"
});

Console.WriteLine("Requesting Raw Stream...");

string json = "{\"StartServerStream\":\"Y\"}";

string route = "quotes";
byte[] intBytes = BitConverter.GetBytes(6);
string stringBytes = Encoding.Default.GetString(intBytes, 0, 1);
string metaData = stringBytes + route;

var stringclient = new RSocketClient.ForStrings(client);
await stringclient.RequestStream(json, metaData)
    .ForEachAsync((result) =>
    {
        Console.WriteLine($"Result ===> {result}");
    }); 

The server uses webflux to stream back to the client. Get the RSocket.Core and put a breakpoint at https://github.com/rsocket/rsocket-net/blob/master/RSocket.Core/RSocketProtocol.Handler.cs#L30

If you watch the message sizes coming in, the 1st message size is what you expect from your server (fielding dummy messages) but the next message sizes are unexpected.