Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet-watch run fails to reload on Debian machines that do not have the procps package installed #27950

Closed
MichaelSimons opened this issue Nov 18, 2020 · 3 comments
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI bug This issue describes a behavior which is not expected - a bug. feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Milestone

Comments

@MichaelSimons
Copy link
Member

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

  1. Create a new simple "Hello world" webapp
mkdir /tmp/test && cd /tmp/test
dotnet new web
  1. 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

  1. The mcr.microsoft.com/dotnet/sdk:5.0 image in this scenario is based on Debian. Installing the procps package resolves the issue.
  2. This is what I found with a quick investigation.

https://github.com/dotnet/aspnetcore/blob/master/src/Tools/dotnet-watch/src/Internal/ProcessRunner.cs#L164

_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);

  1. In discussing this with @pranavkm, it seems plausible that the KillTree implementation could be replaced with System.Diagnostrics.Process.Kill(bool entireProcessTree). This would be desirable as it would remove this native dependency.
  2. 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 dependency dotnet-watch has was unknown to all parties involved.
@MichaelSimons MichaelSimons added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Nov 18, 2020
@mkArtakMSFT mkArtakMSFT added this to the 5.0.1 milestone Nov 19, 2020
@mkArtakMSFT mkArtakMSFT added the feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) label Nov 19, 2020
@mkArtakMSFT mkArtakMSFT modified the milestones: 5.0.1, 5.0.2 Nov 30, 2020
@ghost
Copy link

ghost commented Dec 9, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@jkotalik jkotalik removed their assignment Jan 22, 2021
@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. and removed Working labels Jan 25, 2021
@MichaelSimons
Copy link
Member Author

@mkArtakMSFT - Can this get scheduled for 6.0?

cc /@richlander

@pranavkm
Copy link
Contributor

Resolved as part of dotnet/sdk#15821.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI bug This issue describes a behavior which is not expected - a bug. feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@pranavkm @MichaelSimons @jkotalik @mkArtakMSFT and others