dotnet / dotnet/runtime

Normal operations inner exceptions of ManagedWebsocket lead to big percentage of all thrown exceptions

Open
#119,843 2 comments 0 reactions 0 assignees View on GitHub
area-System.Net
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

Any big websocket service will naturally have clients suddenly disconnecting, sending cancelled, etc. There's almost no way to proactively guard from it. Current design of .NET BCL means this events lead to exception. That much is expected.

Even if one tries to proactively limit the number of actually thrown exceptions via configureoptions `SuppressThrowing`, there's still a _lot of_ exceptions thrown within the ManagedWebSocket for control flow.

Namely we see following callstacks (most often ReceiveAsyncPrivate):

Image

Image

Image

### Configuration

Windows, http.sys, .NET 9; but it seems to be not tied to either platform of http server.

### Regression?

No

### Data

See above

### Ask:

I understand big changes might be problematic, but wouldn't it be possible to change ReceiveAsyncPrivate to do controll flow _without_ throwin (and frequently catching) exceptions? But instead just return?

### Analysis

Exceptions above are > 10 % of all exceptions thrown in our (very big) websocket as a service service (hundreds of millions users daily).

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.