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

Dispose all subscriptions when connection broken #677

Merged
merged 13 commits into from
Dec 28, 2021
Merged

Conversation

Shane32
Copy link
Member

@Shane32 Shane32 commented Dec 26, 2021

This code ensures that all existing subscriptions are disposed when the connection is disposed. Of course if the shutdown is clean then there should be no difference. Also it prevents additional subscriptions from connecting after the connection is disposed. Also the subscription releases all held objects upon disposal - so in case the IObserverable does not properly release the observer after it is disposed, at least there won't be any held handles to the underlying WebSocket.

@Shane32 Shane32 requested a review from sungam3r December 26, 2021 16:50
@Shane32 Shane32 self-assigned this Dec 26, 2021
@sungam3r
Copy link
Member

approvals?

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@github-actions github-actions bot added the test label Dec 26, 2021
@Shane32
Copy link
Member Author

Shane32 commented Dec 26, 2021

approvals?

Whoops! Should be good now.

@Shane32
Copy link
Member Author

Shane32 commented Dec 26, 2021

@sungam3r Merge if it looks good to you.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Shane32
Copy link
Member Author

Shane32 commented Dec 27, 2021

@sungam3r Ready for review here.

@Shane32 Shane32 added this to the v5.2 milestone Dec 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Shane32
Copy link
Member Author

Shane32 commented Dec 28, 2021

Just checked the code:

WebSocketConnectionFactory.CreateConnection:

  • Creates WebSocketTransport and SubscriptionManager.
    • The WebSocketTransport disposes the underlying WebSocket
    • The SubscriptionManager disposes any Subscriptions it creates in a thread-safe manner.
      • Subscription instances dispose the underlying IDisposable returned from subscribing
  • Creates SubscriptionServer which owns (and disposes) the SubscriptionManager and references the WebSocketTransport.
  • Creates WebSocketConnection which owns (and disposes) WebSocketTransport and SubscriptionServer.
    • The WebSocketConnection is disposed by the using statement in the middleware for ASP.Net Core (GraphQLWebSocketsMiddleware).

This may sound confusing, but I'm pretty sure it's all correct.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@codecov-commenter
Copy link

Codecov Report

Merging #677 (8723272) into master (7017816) will decrease coverage by 2.22%.
The diff coverage is 23.40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #677      +/-   ##
==========================================
- Coverage   52.44%   50.22%   -2.23%     
==========================================
  Files          68       68              
  Lines        1779     1818      +39     
  Branches      172      183      +11     
==========================================
- Hits          933      913      -20     
- Misses        798      851      +53     
- Partials       48       54       +6     
Impacted Files Coverage Δ
...s.Subscriptions.Abstractions/SubscriptionServer.cs 94.04% <0.00%> (-1.14%) ⬇️
...ts.Subscriptions.WebSockets/WebSocketConnection.cs 0.00% <0.00%> (ø)
....Subscriptions.Abstractions/SubscriptionManager.cs 66.97% <4.00%> (-18.91%) ⬇️
...nsports.Subscriptions.Abstractions/Subscription.cs 80.95% <50.00%> (-15.05%) ⬇️
....Subscriptions.Abstractions/LogMessagesListener.cs 0.00% <0.00%> (-40.00%) ⬇️
src/Core/Extensions/ServiceCollectionExtensions.cs 56.52% <0.00%> (-26.09%) ⬇️
src/Core/DefaultGraphQLExecuter.cs 0.00% <0.00%> (-25.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7017816...8723272. Read the comment docs.

@Shane32 Shane32 merged commit fe040c8 into master Dec 28, 2021
@Shane32 Shane32 deleted the dispose_subscription branch December 28, 2021 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants