microsoft / vs-streamjsonrpc

The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Other
730 stars 149 forks source link

SystemTextJsonFormatter throws exceptions when ETW logging is enabled #1038

Closed dibarbet closed 4 months ago

dibarbet commented 4 months ago

I've been working on converting the Roslyn LSP server to STJ in https://github.com/dotnet/roslyn/pull/73207

When validating the changes in VS, I hit a huge number of exception count regressions (thousands in some scenarios), see this internal link. These regressions were not reproducible in my changes locally, nor in the build from the VS insertion, until I either

  1. set the env var StreamJsonRpc_TestWithEventSource
  2. or ran VS under perfview using the streamjsonrpc ETW provider (F0CFFE53-BCC5-53F5-8873-995568808A3B)

The exception stacks in the RPS run pretty much all look like the following: image

It appears as though we're hitting this throw in TryGetArgumentByNameOrIndex - https://github.com/microsoft/vs-streamjsonrpc/blob/f6a3b480bc02f79d73eac256ae3768f51146225a/src/StreamJsonRpc/SystemTextJsonFormatter.cs#L532 because the JsonRpcEventSource is calling to get a string representation of the message with name: null and where JsonArguments is JsonValueKind.Object - https://github.com/microsoft/vs-streamjsonrpc/blob/f6a3b480bc02f79d73eac256ae3768f51146225a/src/StreamJsonRpc/JsonRpcEventSource.cs#L297