Skip to content

Commit 794c22c

Browse files
Dispose CTS in HubConnection streaming (#51138)
Co-authored-by: Brennan <brecon@microsoft.com>
1 parent e3a3257 commit 794c22c

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
@@ -777,7 +777,7 @@ async Task ReadChannelStream()
777777
}
778778
}
779779

780-
return CommonStreaming(connectionState, streamId, ReadChannelStream);
780+
return CommonStreaming(connectionState, streamId, ReadChannelStream, tokenSource);
781781
}
782782

783783
// this is called via reflection using the `_sendIAsyncStreamItemsMethod` field
@@ -794,11 +794,14 @@ async Task ReadAsyncEnumerableStream()
794794
}
795795
}
796796

797-
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream);
797+
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream, tokenSource);
798798
}
799799

800-
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream)
800+
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream, CancellationTokenSource cts)
801801
{
802+
// make sure we dispose the CTS created by StreamAsyncCore once streaming completes
803+
using var _ = cts;
804+
802805
Log.StartingStream(_logger, streamId);
803806
string? responseError = null;
804807
try

0 commit comments

Comments
 (0)