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

[release/6.0] Dispose CTS in HubConnection streaming #51139

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ async Task ReadChannelStream()
}
}

return CommonStreaming(connectionState, streamId, ReadChannelStream);
return CommonStreaming(connectionState, streamId, ReadChannelStream, tokenSource);
}

// this is called via reflection using the `_sendIAsyncStreamItemsMethod` field
Expand All @@ -760,11 +760,14 @@ async Task ReadAsyncEnumerableStream()
}
}

return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream);
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream, tokenSource);
}

private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream)
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream, CancellationTokenSource cts)
{
// make sure we dispose the CTS created by StreamAsyncCore once streaming completes
using var _ = cts;

Log.StartingStream(_logger, streamId);
string? responseError = null;
try
Expand Down