Skip to content

Commit 0c61054

Browse files
Dispose CTS in HubConnection streaming (#51137)
Co-authored-by: Brennan <[email protected]>
1 parent 954413f commit 0c61054

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
@@ -853,7 +853,7 @@ async Task ReadChannelStream()
853853
}
854854
}
855855

856-
return CommonStreaming(connectionState, streamId, ReadChannelStream);
856+
return CommonStreaming(connectionState, streamId, ReadChannelStream, tokenSource);
857857
}
858858

859859
// this is called via reflection using the `_sendIAsyncStreamItemsMethod` field
@@ -870,11 +870,14 @@ async Task ReadAsyncEnumerableStream()
870870
}
871871
}
872872

873-
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream);
873+
return CommonStreaming(connectionState, streamId, ReadAsyncEnumerableStream, tokenSource);
874874
}
875875

876-
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream)
876+
private async Task CommonStreaming(ConnectionState connectionState, string streamId, Func<Task> createAndConsumeStream, CancellationTokenSource cts)
877877
{
878+
// make sure we dispose the CTS created by StreamAsyncCore once streaming completes
879+
using var _ = cts;
880+
878881
Log.StartingStream(_logger, streamId);
879882
string? responseError = null;
880883
try

0 commit comments

Comments
 (0)