Skip to content

Commit

Permalink
[release/6.0] Dispose CTS in HubConnection streaming (#51139)
Browse files Browse the repository at this point in the history
* Dispose CTS in HubConnection streaming

* Apply suggestions from code review

Co-authored-by: Stephen Halter <halter73@gmail.com>

---------

Co-authored-by: Brennan <brecon@microsoft.com>
Co-authored-by: Stephen Halter <halter73@gmail.com>
  • Loading branch information
3 people authored Oct 5, 2023
1 parent 9104f71 commit 20f37ce
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 20f37ce

Please sign in to comment.