Skip to content

Commit

Permalink
Dispose CTS in HubConnection streaming (#51138)
Browse files Browse the repository at this point in the history
Co-authored-by: Brennan <[email protected]>
  • Loading branch information
github-actions[bot] and BrennanConroy authored Oct 5, 2023
1 parent e3a3257 commit 794c22c
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 @@ -777,7 +777,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 @@ -794,11 +794,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 794c22c

Please sign in to comment.