dotnet / dotnet/aspnetcore

Provide an extra private readonly property on the SignalR HubConnectionContext

Open
#59,346 8 comments 0 reactions 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Currently there is no way for us to know way to calculate size of the payload content sent to signal r.
As confirmed in https://github.com/dotnet/aspnetcore/issues/59335#issuecomment-2521029996

Not having any mechanism to determine this size makes it very difficult to accurately set the ``MaximumReceiveMessageSize`` for SignalR.

### Describe the solution you'd like

As we already have a bunch of private readonly properties we can inspect on the HubConnectionContext when we break on the ``InvalidDataException`` inside ``DispatchMessagesAsync`` while in debug mode with ``Common Language Runtime Exceptions`` enabled as shown below.
![Image](https://github.com/user-attachments/assets/0a51648e-5c46-4ec3-a0a0-9c48a7e84835)

Please add an additional private readonly property which only contains the buffer length that is used to compare against the ``maxMessageSize`` inside
```
if (segment.Length > maxMessageSize)
{
segment = segment.Slice(segment.Start, maxMessageSize);
overLength = true;
}
```

The ability to understand the message size sent to appropriately adjust the ``MaximumReceiveMessageSize`` is highly requested, searched for and mentioned in Stackover and Reddit.

We don't need any sort of mechanism to calculate the payload size programmatically, but we do need a way to know what the ``MaximumReceiveMessageSize`` is compared against to ensure we have a large enough ceiling while also not sacrificing performance.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.