Skip to content

Commit 91c5c96

Browse files
committed
fix: accessing dummy in multi-threads throws exception
Signed-off-by: leo <[email protected]>
1 parent 2fc0302 commit 91c5c96

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Commands/Command.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public bool Exec()
7373
};
7474

7575
var dummy = null as Process;
76+
var dummyProcLock = new object();
7677
try
7778
{
7879
proc.Start();
@@ -83,11 +84,10 @@ public bool Exec()
8384
dummy = proc;
8485
CancellationToken.Register(() =>
8586
{
86-
if (dummy is { HasExited: false })
87+
lock (dummyProcLock)
8788
{
88-
dummy.CancelErrorRead();
89-
dummy.CancelOutputRead();
90-
dummy.Kill();
89+
if (dummy is { HasExited: false })
90+
dummy.Kill();
9191
}
9292
});
9393
}
@@ -104,7 +104,14 @@ public bool Exec()
104104
proc.BeginErrorReadLine();
105105
proc.WaitForExit();
106106

107-
dummy = null;
107+
if (dummy != null)
108+
{
109+
lock (dummyProcLock)
110+
{
111+
dummy = null;
112+
}
113+
}
114+
108115
int exitCode = proc.ExitCode;
109116
proc.Close();
110117

0 commit comments

Comments
 (0)