Skip to content

Commit 4c4ba92

Browse files
authored
Merge pull request #1005 from Flow-Launcher/KillProcess
Use Cancellation Token to avoid potential race tracing issue
2 parents 886eb86 + 0ceefea commit 4c4ba92

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected string Execute(ProcessStartInfo startInfo)
241241
protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, CancellationToken token = default)
242242
{
243243
Process process = null;
244-
bool disposed = false;
244+
using var exitTokenSource = new CancellationTokenSource();
245245
try
246246
{
247247
process = Process.Start(startInfo);
@@ -251,6 +251,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
251251
return Stream.Null;
252252
}
253253

254+
254255
await using var source = process.StandardOutput.BaseStream;
255256

256257
var buffer = BufferManager.GetStream();
@@ -259,7 +260,7 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
259260
{
260261
// ReSharper disable once AccessToModifiedClosure
261262
// Manually Check whether disposed
262-
if (!disposed && !process.HasExited)
263+
if (!exitTokenSource.IsCancellationRequested && !process.HasExited)
263264
process.Kill();
264265
});
265266

@@ -302,8 +303,8 @@ protected async Task<Stream> ExecuteAsync(ProcessStartInfo startInfo, Cancellati
302303
}
303304
finally
304305
{
306+
exitTokenSource.Cancel();
305307
process?.Dispose();
306-
disposed = true;
307308
}
308309
}
309310

0 commit comments

Comments
 (0)