JsonHubProtocol does not use PayloadSerializerOptions.MaxDepth when parsing invocation envelopes
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I searched the existing issues
The closest issue is #51254, but that issue concerns `NewtonsoftJsonHubProtocol`. This report concerns the default System.Text.Json-based `JsonHubProtocol`.
`JsonHubProtocolOptions.PayloadSerializerOptions.MaxDepth` is respected when SignalR deserializes an individual argument, but it is not used while parsing the surrounding SignalR invocation envelope.
`JsonHubProtocol` constructs its envelope reader with the default reader state:
```csharp
new Utf8JsonReader(input, isFinalBlock: true, state: default)
```
This gives the envelope reader the System.Text.Json default maximum depth of 64. Because that reader traverses the complete arguments array before argument binding, an argument nested beyond that depth is rejected before PayloadSerializerOptions can deserialize it.
Why this cannot be handled by application converters
The exception occurs while JsonHubProtocol scans the invocation envelope, before the argument is passed to JsonSerializer.Deserialize. Custom converters and PayloadSerializerOptions therefore cannot intercept or correct the failure.
The available application-level workarounds require either:
changing the wire contract so the nested argument is sent as an escaped JSON string, or
replacing the built-in IHubProtocol implementation.
Contributor guide
Research direction
Start at the JsonHubProtocol entry point that constructs Utf8JsonReader with the default reader state, then inspect nearby protocol tests for envelope parsing and MaxDepth behavior. Confirm that the invocation envelope honors PayloadSerializerOptions.MaxDepth while preserving the existing argument deserialization behavior, and add or update coverage for deeply nested arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 64/100