Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Squash fix for process name. - #36913

Merged
danmoseley merged 9 commits into
dotnet:masterfrom
2E0PGS:b/linux-proc-name-char
Apr 20, 2019
Merged

danmoseley merged 9 commits into
dotnet:masterfrom
2E0PGS:b/linux-proc-name-char

Conversation

@2E0PGS

@2E0PGS 2E0PGS commented Apr 16, 2019

Copy link
Copy Markdown
Contributor

@dnfclas

dnfclas commented Apr 16, 2019 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@MarcoRossignoli

Copy link
Copy Markdown
Member

/cc @danmosemsft @krwq @wtgodbe


// Get long process name if possible, otherwise use a fall back method.
string procName = Path.GetFileName(Process.GetExePath(pid));
if (String.IsNullOrEmpty(procName))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: String => string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes correct however functionality is the same here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes normally I would use string I must of mistyped. Basic types vs complex, string is fine but DateTime is a complex type etc.

Assert.True(p.HasExited);
}

[Fact]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is only meant to work on Linux, right? If so, can you please move it to the ProcessTests.Unix.cs file and also add a [PlatformSpecific(TestPlatforms.Linux)] attribute to the test?

@MarcoRossignoli MarcoRossignoli Apr 18, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is only meant to work on Linux, right?

Actually should be for Linux/Mac, but it doesn't work for Mac.

If so, can you please move it to the ProcessTests.Unix.cs file and also add a [PlatformSpecific(TestPlatforms.Linux)] attribute to the test?

I did it, but after Dan's review I moved it #36880 (comment)
Maybe we could keep here with [PlatformSpecific(~TestPlatforms.OSX)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have

[PlatformSpecific(TestPlatforms.AnyUnix)]
[ActiveIssue(XXXX, TestPlatforms.OSX)]

where XXXX is some separately issue you open for someone to figure out how to make this work on Mac.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank's forgot that ActiveIssue exclude plat.

}
}
px.Kill();
px.WaitForExit();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be better to have these, in particular the Kill, in a finally block, so that if some unexpected error happens, we don't leave a process running on the machine. We can also utilize Assert.Contains to simplify this whole thing, e.g.

try
{
    Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName);
}
finally
{
    px.Kill();
    px.WaitForExit();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

{
string commandName = "sleep";

// sleep program doesn't exist on some flavor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does / doesn't it exist?

@MarcoRossignoli MarcoRossignoli Apr 18, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a Dan suggestion https://github.com/dotnet/corefx/issues/34437#issuecomment-460097674 /cc @danmosemsft
I don't know all distros so well, I cannot answer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep is part of GNU coreutils. quite common on modern UNIX systems that support bash. However there maybe a different set of params for sleep on OSX.

@danmoseley

Copy link
Copy Markdown

Does Mac still have the original bug? If so it's fine to fix for Linux for now, but we should have a new issue for Mac


// Get long process name if possible, otherwise use a fall back method.
string procName = Path.GetFileName(Process.GetExePath(pid));
if (String.IsNullOrEmpty(procName))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under what conditions can this happen?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the backgroud of investigation I think it's better left @2E0PGS to answer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you see the issue for this PR there is some background for this solution: https://github.com/dotnet/corefx/issues/34437

@MarcoRossignoli

Copy link
Copy Markdown
Member

@stephentoub @danmosemsft @krwq fails also on Alpine...but in previous CI I saw only OSX fail...is apline leg new?

{
try
{
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName);

@am11 am11 Apr 19, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sleep is available as a busybox command on Alpine. If we do sleep 30 &\ ; ps uax, we get sleep 30 job running in background (or run jobs after sleep 30 &). But if we follow the symlink (/bin/sleep), it points to /bin/busybox.

readlink $(command -v sleep) -> /bin/busybox

Test failure:
image

one of these busybox processes are sleep. We can assert with PID to confirm:

try
{
    Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName);
}
catch(ContainsException)
{
    // on Alpine, sleep is a symlink which points to /bin/busybox
    Assert.Contains(Process.GetProcesses(), p => p.ProcessName == "busybox" && p.ProcessId == px.ProcessId);
}

or simply:

 // on Alpine, sleep is a symlink which points to /bin/busybox
Assert.Contains(Process.GetProcesses(), p => p.ProcessName == longProcessName || ( p.ProcessName == "busybox" && p.ProcessId == px.ProcessId));

@MarcoRossignoli MarcoRossignoli Apr 19, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I wonder why first time I ran CI all works well(except OSX), maybe is a new CI leg.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@am11 thank's!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still failed with same error. Maybe we can try adding some temporary debug info in catch to find out some details:

var runninProcesses = Process.GetProcesses();
try
{
    Assert.Contains(runninProcesses, ...
}
catch(ContainsException)
{
    Assert.False(true, $"Expected ID {px.Id} in collection: [" + string.Join(" ,", runninProcesses.Select(p => $"{p.Name}({p.Id})")) + "]");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried to setup an Alpine image but I've got some issue with packages...try with CI

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be fine to open a separate issue to add a test for Alpine. Maybe using a custom library like NativeLibrary tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoRossignoli, based on @danmosemsft's suggestion, we can revert changes made in 0c53c36, c8e1287 and cb11900 (or simply git reset --hard 790de76) and apply something like the following:

             // sleep program doesn't exist on some flavor
+            // in flavors such as Alpine, sleep is a busybox command which cannot be renamed
+            // TODO (##github-issue##): build a custom long-running executable for this test instead of sleep
-             if (!IsProgramInstalled(commandName))
+             if (!IsProgramInstalled(commandName) || IsProgramInstalled("busybox"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps ping 127.0.0.1 can act as your long running command?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krwq good thinking, but ping is busybox too, unfortunately:

DESKTOP-CJJBOPC:~# readlink $(command -v sleep)
/bin/busybox
DESKTOP-CJJBOPC:~# readlink $(command -v ping)
/bin/busybox

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok will do with revert and skip on busybox system

@danmoseley

danmoseley commented Apr 19, 2019 •

Copy link
Copy Markdown

It seems it passed this time - which seems a bit random. I don't see why we got a different result. Could it be that the "sleep" is returning almost instantly on Alpine?

But what are you hoping the test will do on Alpine? The purpose of the test is to verify that p.ProcessName returns the 30 character name. If we know on Alpine that it will return "busybox" then the test has no value anyway. You either have to copy "busybox" itself and then invoke it like sleep, or (if it's not important) make this test skip on Alpine.

[edit, I see comment above now.]

@danmoseley
danmoseley merged commit 8b515ad into dotnet:master Apr 20, 2019
stephentoub added a commit that referenced this pull request Apr 23, 2019
stephentoub added a commit that referenced this pull request Apr 23, 2019
@karelz karelz added this to the 3.0 milestone May 4, 2019
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Handle long process names on Linux 

See: https://github.com/2E0PGS/corefx/commit/dotnet/corefx@56e73858adb046b57165eae44af111d64e2fcd98

* add test

* update test

* update test

* address PR feedback

* fix alpine ci

* fix compilation

* add some log for alpine fail

* address PR feedback


Commit migrated from dotnet/corefx@8b515ad
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants