Skip to content

Commit 220db44

Browse files
committed
Manually kill process when token is canceled
1 parent 4e3746f commit 220db44

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,18 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
243243
return Stream.Null;
244244
}
245245

246-
var source = process.StandardOutput.BaseStream;
246+
await using var source = process.StandardOutput.BaseStream;
247247

248248
var buffer = BufferManager.GetStream();
249+
bool disposed = false;
250+
process.Disposed += (_, _) => { disposed = true; };
251+
token.Register(() =>
252+
{
253+
if (!disposed)
254+
// ReSharper disable once AccessToDisposedClosure
255+
// Manually Check whether disposed
256+
process.Kill();
257+
});
249258

250259
try
251260
{
@@ -260,7 +269,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
260269
buffer.Seek(0, SeekOrigin.Begin);
261270

262271
token.ThrowIfCancellationRequested();
263-
272+
264273
if (!process.StandardError.EndOfStream)
265274
{
266275
using var standardError = process.StandardError;

0 commit comments

Comments
 (0)