Skip to content

Commit 20f37ce

Browse files
github-actions[bot]BrennanConroyhalter73
authored
[release/6.0] Dispose CTS in HubConnection streaming (#51139)
* Dispose CTS in HubConnection streaming * Apply suggestions from code review Co-authored-by: Stephen Halter <[email protected]> --------- Co-authored-by: Brennan <[email protected]> Co-authored-by: Stephen Halter <[email protected]>
1 parent 9104f71 commit 20f37ce

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ async Task ReadChannelStream()
743743
}
744744
}
745745

746-
return CommonStreaming(connectionState, streamId, ReadChannelStream);
746+
return CommonStreaming(connectionState, streamId, ReadChannelStream, tokenSource);
747747
}
748748

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

763-
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream);
763+
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream, tokenSource);
764764
}
765765

766-
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream)
766+
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream, CancellationTokenSource cts)
767767
{
768+
// make sure we dispose the CTS created by StreamAsyncCore once streaming completes
769+
using var _ = cts;
770+
768771
Log.StartingStream(_logger, streamId);
769772
string? responseError = null;
770773
try

0 commit comments

Comments
 (0)