Search for the diagnostics socket in the mount NS of the target process #3539
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #3480
This is a PoC for #3480 .
I tested the PoC by:
mcr.microsoft.com/dotnet/sdk:6.0-focal
).main
branch and ran it - I get:Sanity passes.
I had to fix 2 sites:
/proc/pid/root/...
/proc/pid/status
for that.TODOs
/proc/pid/root
by default. This requires privileges (I think it requires to be able to ptrace the process?) and dotnet-trace itself doesn't require root (I actually don't know which permission checks are implemented in the CLR before handling requests on the diagnostics socket. I know that in Java, HotSpot will compare the UID GID of the connecting process to the UID GID of itself). What makes sense, in order to maintain compatibility with the old versions of dotnet-trace, is to fallback to useIpcRootPath
if we couldn't use/proc/pid/root
. We can also check/proc/pid/ns/mnt
vs/proc/self/ns/mnt
to understand if we actually need to move mount namespace, but that requires ptrace permissions as well, so the first check ("can we use /proc/pid/root") is enough IMO./proc/pid/root/...
which can fail if the added path contains absolute symlinks. The problem is explained thoroughly and a solution is given in Python here, this will affect profiled containers if their/tmp
is e.g a link to/var/tmp
. We can resolve it now or in a follow-up PR./proc/pid/status
. This is available from Linux 4.1. If we want to support this feature on older kernels, there is a different method to get the NSpid, if we want to support that.dotnet-trace ps
uses). I don't think there's a way to properly "ps" all dotnet processes by their sockets, because this will require iterating over all mount namespaces? Or over all mount namespaces of alldotnet
process? IDK. I suggest we skip that./tmp
for the temporary directory. Previous code usedPath.GetTempPath
which getsTMPDIR
from env, or defaults to/tmp
. Since that's the same path the diagnostics socket will be created in - what makes sense is to implement the behavior ofGetTempPath
for the remote process, i.e read its environment variables and use/proc/pid/root/$TMPDIR
ifTMPDIR
is present, and otherwise fallback to/tmp
. Can probably be a follow-up PR but I'm just stating it. Btwdotnet-trace collect --process-id
as of now wouldn't have worked on it processes on the same mount namespace if they change theirTMPDIR
Which of these TODOs do you think I should get done for merging it? I think only the first one is needed for MVP, to avoid regressions, and all others are features on top of it. If you agree I can implement it and we can move forward with merging this PR :)