Closed
Description
Describe the bug
dotnet-watch
has some undocumented native dependencies. Specifically it depends on the pgrep
command which is not installed on a clean Debian machine. dotnet-watch run
silently fails to reload when the dependency is not present.
To Reproduce
Copied from dotnet/dotnet-docker#2396
Requirements: Linux Docker environment and the .NET 5 CLI
- Create a new simple "Hello world" webapp
mkdir /tmp/test && cd /tmp/test
dotnet new web
- Run it with
dotnet watch run
and the code mounted in a container
docker run -it --rm --workdir /app -v ${PWD}/:/app mcr.microsoft.com/dotnet/sdk:5.0 dotnet watch run
You'll notice that when opening, altering and saving the ./Startup.cs
file, the service isn't reloaded.
Further technical details
- The
mcr.microsoft.com/dotnet/sdk:5.0
image in this scenario is based on Debian. Installing theprocps
package resolves the issue. - This is what I found with a quick investigation.
_process.KillTree();
https://github.com/dotnet/aspnetcore/blob/master/src/Shared/Process/ProcessExtensions.cs#L20
public static void KillTree(this Process process, TimeSpan timeout)
{
var pid = process.Id;
if (_isWindows)
{
...
}
else
{
var children = new HashSet<int>();
GetAllChildIdsUnix(pid, children, timeout);
foreach (var childId in children)
{
KillProcessUnix(childId, timeout);
}
KillProcessUnix(pid, timeout);
}
}
private static void GetAllChildIdsUnix(int parentId, ISet<int> children, TimeSpan timeout)
{
try
{
RunProcessAndWaitForExit(
"pgrep",
$"-P {parentId}",
timeout,
out var stdout);
- In discussing this with @pranavkm, it seems plausible that the
KillTree
implementation could be replaced withSystem.Diagnostrics.Process.Kill(bool entireProcessTree)
. This would be desirable as it would remove this native dependency. - This was discovered while investigating a 5.0 regression with the .NET SDK Docker image. The
procps
package was removed in 5.0 as part of an effort to reduce the image size in order to provide a better UX. The dependencydotnet-watch
has was unknown to all parties involved.