0

I configured signalr diagnostics to help track down messages from client to server that were not reaching the server... I uncovered the following exception detail which is pretty much what I suspected was happening.

    SignalR.Transports.WebSocketTransport Error: 0 : OnError(08af5ad0-d63d-42a3-8e00-3c109da3be6b, System.InvalidOperationException: Buffer length exceeded
   at Microsoft.AspNet.SignalR.Infrastructure.ByteBuffer.Append(Byte[] segment)
   at Microsoft.AspNet.SignalR.WebSockets.WebSocketMessageReader.<ReadMessageAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<ProcessWebSocketRequestAsync>d__8.MoveNext())

From the packages.config; this is the SignalR version details

  <package id="Microsoft.AspNet.SignalR" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.2" targetFramework="net45" />

I am using SignalR as a javascript library test framework. SignalR allows the server to invoke client side js lib functions which involve invoking other webservices or establishing connections to other websockets and processing async feeds.

I have encountered one particular js lib function which invokes a json webservice and the response is sufficiently large to exceed the signalR internal buffers.

So, what is the maximum buffer length? Is it configurable?

If not; does signalR support message chunking? Or will I need to implement a solution of my own?

Dave Lawrence
  • 3,843
  • 2
  • 21
  • 35
  • 1
    No it doesn't support any chunking today nor do we expect messages sent over SignalR to be this big (it's a security concern since things are buffered in memory). What are you sending that's > 4MB? – davidfowl Dec 04 '13 at 14:20
  • The response to a GetAccountStatement web service call... Basically a very large collection of account postings. But since I posted the question; I implemented a simple chunking mechanism as a workaround. Simply sending one item of the collection at a time from the client to the server and have the server rebuild the collection. I expected that I would need a workaround. Thanks for the response. – Dave Lawrence Dec 04 '13 at 14:27
  • @dfowler Hold on; you said greater than 4MB??? I seriously doubt that the message response would ever have exceeded 4MB. Are you sure for the version of SignalR I'm using that the max message size or max buffer size is 4MB? Is there a way which I can measure/record message sizes? – Dave Lawrence Dec 05 '13 at 12:23
  • https://github.com/SignalR/SignalR/blob/1.1.2/src/Microsoft.AspNet.SignalR.Owin45/Infrastructure/ByteBuffer.cs#L26 https://github.com/SignalR/SignalR/blob/1.1.2/src/Microsoft.AspNet.SignalR.Owin45/WebSockets/WebSocketMessageReader.cs#L54 It's actually 64K by default: https://github.com/SignalR/SignalR/blob/1.1.2/src/Microsoft.AspNet.SignalR.Owin45/WebSockets/WebSocketHandler.cs#L22 – davidfowl Dec 05 '13 at 18:03
  • Ah ok. That would make sense. As an academic question; I presume that default is not configurable? – Dave Lawrence Dec 09 '13 at 13:07

2 Answers2

2

An old question, but this post (which didn't solve the problem for me) came up from the debths of Google before I found a working solution from here: https://stackoverflow.com/a/39854957/3535681.

So here briefly what helped me in the answer from the link above.

You can add a line that makes the message size 'infinite 'in your Startup.cs by setting the MaxIncomingWebSocketMessageSize to null:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
    app.MapSignalR();
    GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
    }
}

In my case the messages which led to having the Buffer Lenght Exceede error were just over 64K so I only doubled the MaxIncomingWebSocketMessageSize to 128K.

Lupa
  • 81
  • 1
  • 11
0

I suspected that a workaround would be neccessary so I implemented a rather basic chunking mechanism to protect against the message sizes exceeding the buffer limits.

Dave Lawrence
  • 3,843
  • 2
  • 21
  • 35