Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace Microsoft.Diagnostics.NETCore.Client
{
Expand Down Expand Up @@ -297,7 +298,18 @@ private static bool TryGetDefaultAddress(int pid, out string defaultAddress)
{
try
{
defaultAddress = Directory.GetFiles(IpcRootPath, $"dotnet-diagnostic-{pid}-*-socket") // Try best match.
Copy link
Member

Choose a reason for hiding this comment

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

For Kubernetes scenarios with sharedProcessNamespace disabled, wouldn't this preclude the other solution from working? I.e. shared /tmp volume would not work and /proc will not be visible between containers.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, good point. Since dotnet-trace never actually required the PID to be visibile in /proc, we could always just share the /tmp and use --process-id with the NSpid of the process.

I think what will work is - if this path fails (i.e we don't have a valid socket in the /proc/pid/root/tmp/...nspid... path) we will fall back to the old behavior. Makes sense?

Copy link
Member

Choose a reason for hiding this comment

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

That seems like it would work but be aware that in the above environment if two containers are both running managed apps as lead processes, they will both have a pid of 1. This conflict also exists for tmp mounting though.

string status = File.ReadAllText($"/proc/{pid}/status");

Regex regex = new Regex(@"^NSpid:.*(\d+)$", RegexOptions.Multiline);
Match match = regex.Match(status);

int nspid = pid;
if (match.Success)
{
nspid = int.Parse(match.Groups[1].Value);
}

defaultAddress = Directory.GetFiles($"/proc/{pid}/root/tmp", $"dotnet-diagnostic-{nspid}-*-socket") // Try best match.
.OrderByDescending(f => new FileInfo(f).LastWriteTime)
.FirstOrDefault();
}
Expand Down