Skip to content

Commit 60ce762

Browse files
committed
fixing exception when accessing a disposed Process (#9098)
1 parent 0266f36 commit 60ce762

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/WebJobs.Script/Workers/ProcessManagement/WorkerProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public void WaitForProcessExitInMilliSeconds(int waitTime)
218218
}
219219
catch (Exception ex)
220220
{
221-
_workerProcessLogger.LogDebug(ex, "An exception was thrown while waiting for process {processId} to exit. It is possible that the process had already exited and this can be ignored.", Process?.Id);
221+
_workerProcessLogger.LogDebug(ex, "An exception was thrown while waiting for a worker process to exit. It is possible that the process had already exited and this can be ignored.");
222222
}
223223
}
224224

test/WebJobs.Script.Tests/Workers/Rpc/RpcWorkerProcessTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,29 @@ public void CreateWorkerProcess_AddsHostingConfiguration()
214214

215215
_workerProcessFactory.Verify(x => x.CreateWorkerProcess(It.Is<WorkerContext>(c => c.EnvironmentVariables["feature1"] == "1")));
216216
}
217+
218+
[Fact]
219+
public void WorkerProcess_WaitForExit_AfterExit_DoesNotThrow()
220+
{
221+
Process process = new Process();
222+
ProcessStartInfo startInfo = new ProcessStartInfo();
223+
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
224+
startInfo.FileName = "cmd.exe";
225+
startInfo.Arguments = $"ls";
226+
process.StartInfo = startInfo;
227+
process.Start();
228+
229+
_rpcWorkerProcess.Process = process;
230+
_rpcWorkerProcess.Dispose();
231+
232+
_rpcWorkerProcess.WaitForProcessExitInMilliSeconds(1);
233+
234+
var traces = _logger.GetLogMessages();
235+
string msg = traces.Single().FormattedMessage;
236+
Assert.StartsWith("An exception was thrown while waiting for a worker process to exit.", msg);
237+
238+
Exception ex = traces.Single().Exception;
239+
Assert.IsType<InvalidOperationException>(ex);
240+
}
217241
}
218242
}

0 commit comments

Comments
 (0)