Skip to content

Commit

Permalink
Dispose CTS in HubConnection streaming (#51117)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanConroy authored Oct 4, 2023
1 parent 426ed0f commit 9e5ae70
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 @@ -853,7 +853,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 @@ -870,11 +870,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 9e5ae70

Please sign in to comment.