Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 824af33

Browse files
committed
fix: Use shared token on underlying stream process
This way, when the stop command is called, the underlying stream process should be signaled to cancel right away too.
1 parent ce2e286 commit 824af33

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/StreamMaster.Streams/Broadcasters/SourceBroadcaster.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,21 @@ public async Task<long> SetSourceStreamAsync(SMStreamInfo SMStreamInfo, Cancella
106106

107107
this.SMStreamInfo = SMStreamInfo;
108108

109+
// Start a new streaming task
110+
_cancellationTokenSource = new CancellationTokenSource();
111+
109112
Stopwatch stopwatch = Stopwatch.StartNew();
110113
try
111114
{
112115
(Stream? stream, int processId, ProxyStreamError? error) =
113-
await streamFactory.GetStream(SMStreamInfo, cancellationToken).ConfigureAwait(false);
116+
await streamFactory.GetStream(SMStreamInfo, _cancellationTokenSource.Token).ConfigureAwait(false);
114117
stopwatch.Stop();
115118
if (stream == null || error != null)
116119
{
117120
logger.LogError("Could not create source stream for channel broadcaster: {Id} {Name} {Error}", SMStreamInfo.Id, SMStreamInfo.Name, error?.Message);
118121
return 0;
119122
}
120123

121-
// Start a new streaming task
122-
_cancellationTokenSource = new CancellationTokenSource();
123124
_streamingTask = Task.Run(() => RunPipelineAsync(stream, SMStreamInfo.Name, cancellationToken: _cancellationTokenSource.Token), _cancellationTokenSource.Token);
124125
return stopwatch.ElapsedMilliseconds;
125126
}
@@ -193,6 +194,11 @@ private async Task RunPipelineAsync(Stream sourceStream, string name, int buffer
193194
timeoutCts?.Dispose();
194195
}
195196

197+
if (cancellationToken.IsCancellationRequested)
198+
{
199+
break;
200+
}
201+
196202
if (bytesRead == 0)
197203
{
198204
if (!hasReadData)

0 commit comments

Comments
 (0)