Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add KeepAliveMode and SupportedWebSocketSubProtocols options #1154

Merged
merged 11 commits into from
Oct 27, 2024

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Oct 7, 2024

Adds a 'secure' keep-alive mode where:

  • A ping is sent on a timer from the last received pong
  • Ping messages carry a unique payload (random guid)
  • Received pong messages verify the payload
  • If a pong is not received with the correctly id in a timely fashion, the client is forcibly disconnected

Reason:

  • With subscriptions that continuously send lots of data, there is no way to determine if socket backpressure due to slow client connections is causing resource exhaustion. This feature will validate that buffers are drained over the specified time period, as the client would not know what id to send with a pong if it did not process the incoming messages fast enough.

Consider:

  • Name of KeepAliveMode enum values
  • Adding separate timer property that represents the amount of time to wait for a corresponding pong after a sent ping. Currently this just matches the ping timer.

@Shane32 Shane32 self-assigned this Oct 7, 2024
@Shane32 Shane32 marked this pull request as draft October 7, 2024 04:13
@Shane32 Shane32 added this to the 8.1.0 milestone Oct 7, 2024
@Shane32 Shane32 marked this pull request as ready for review October 27, 2024 04:01
@Shane32 Shane32 changed the title Add KeepAliveMode option Add KeepAliveMode and SupportedWebSocketSubProtocols options Oct 27, 2024
Comment on lines +126 to +127
[Obsolete($"Please use the {nameof(OnConnectionInitAsync)} and {nameof(OnKeepAliveLoopAsync)} methods instead. This method will be removed in a future version of this library.")]
protected override Task OnConnectionInitAsync(OperationMessage message, bool smartKeepAlive)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has been carefully crafted to be fully backwards compatible, just in case of the rare instance that someone derived from this class to customize behavior.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 52.17391% with 55 lines in your changes missing coverage. Please review.

Project coverage is 89.06%. Comparing base (a84c553) to head (2141f56).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...NetCore/WebSockets/GraphQLWs/SubscriptionServer.cs 40.00% 42 Missing and 3 partials ⚠️
...ts.AspNetCore/WebSockets/BaseSubscriptionServer.cs 71.42% 5 Missing and 3 partials ⚠️
...ets/SubscriptionsTransportWs/SubscriptionServer.cs 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1154      +/-   ##
==========================================
- Coverage   90.88%   89.06%   -1.82%     
==========================================
  Files          50       51       +1     
  Lines        2425     2543     +118     
  Branches      432      450      +18     
==========================================
+ Hits         2204     2265      +61     
- Misses        175      224      +49     
- Partials       46       54       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Shane32 Shane32 merged commit 0ef7f46 into master Oct 27, 2024
7 checks passed
@Shane32 Shane32 deleted the keepalivemode branch October 27, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants