diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

`dotnet-dump collect` silently fails if the user running the process does not have permission to write

Open xPaw opened this issue 9 months ago • 1 comments

$ dotnet-dump collect -p 736578

Writing full to /home/xpaw/core_20250211_130126
Complete

But in reality the file was not actually written, because the process I was dumping was running as another user (I ran the dump command as root) which didn't have permissions to write to my home folder. When I changed working directory to /tmp it actually worked.

The tool should report an error if it fails to actually write the file instead of saying complete.

I am using .NET 9.0.102 on Debian 12.

xPaw avatar Feb 11 '25 13:02 xPaw

There's two issues:

  • the IPC should have an error code.
  • The errors are directed stream - it should have displayed on your side.

hoyosjs avatar Feb 11 '25 23:02 hoyosjs

I am not able to reproduce this issue. What is the output of dotnet-dump --version?

rcj1 avatar Jun 28 '25 02:06 rcj1

It was 9.0.553101, highly unlikely that this was fixed in newer release.

Your working directory needs to be a path that the running process has no permission to.

xPaw avatar Jun 28 '25 08:06 xPaw

I am still unable to reproduce the issue. I have your version of Debian, .NET, and dotnet-dump. When I run dotnet-dump in a directory where the running process has rwx permissions, I receive the following success messages: Image Image

When I run it in a directory where the running process has rx permissions, I receive the following error messages:

Image Image

Did you run dotnet-dump ps to find the appropriate PID? The PID that you wish to dump from must be listed here.

rcj1 avatar Jun 30 '25 17:06 rcj1

I don't know where the [createdump] messages are from, because I only see the "writing full to... complete" with the dump command.

xPaw avatar Jun 30 '25 19:06 xPaw

The createdump messages are on the to-be-dumped process's side. Does your PID that you are attempting to dump appear in dotnet-dump ps?

rcj1 avatar Jun 30 '25 19:06 rcj1

I think that's kind of the point, if you run the dump command without actively reading the output of the running process, you can't see it fail.

xPaw avatar Jun 30 '25 20:06 xPaw

That is not what I see on my end, if you look at the images you will see two images for the failure, one on the dotnet-dump side and one on the other process side.

rcj1 avatar Jun 30 '25 21:06 rcj1

I just tried it now. I don't see [createdump] logs on the collect side, I do see them on the process side, however there is no permission error being logged here either (despite the process not running as root)

[createdump] Gathering state for process xxx
[createdump] Writing full dump to file /root/.dotnet/tools/core_20250630_212037
[createdump] Target process is alive

And no dump was written. When I Ctrl-C'd the running process, it finally logged:

[createdump] Could not create output file '/root/.dotnet/tools/core_20250630_212037': Permission denied (13)

xPaw avatar Jun 30 '25 21:06 xPaw

Could you try again with a dummy program that runs an infinite loop, with no debugger connected and running solely through dotnet run?

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
        }
    }
}

How do you run this program, for example is there a debugger attached?

rcj1 avatar Jun 30 '25 23:06 rcj1

The missing piece of information was that this only reproduces for PublishSingleFile builds.

dotnet publish -c release

<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>

single file:

$ ./bin/release/net9.0/linux-x64/publish/test
[createdump] Gathering state for process 3587386 test
[createdump] Writing full dump to file /root/.dotnet/tools/core_20250701_073539
[createdump] Target process is alive
^C

---

$ ./dotnet-dump collect -p 3587386
Writing full to /root/.dotnet/tools/core_20250701_073539
Complete

just self contained:

$ ./bin/release/net9.0/linux-x64/publish/test
[createdump] Gathering state for process 3588036 test
[createdump] Writing full dump to file /root/.dotnet/tools/core_20250701_073638
[createdump] Target process is alive
[createdump] Could not create output file '/root/.dotnet/tools/core_20250701_073638': Permission denied (13)
[createdump] Failure took 70ms

---

$ ./dotnet-dump collect -p 3588036
Writing full to /root/.dotnet/tools/core_20250701_073638
[createdump] Could not create output file '/root/.dotnet/tools/core_20250701_073638': Permission denied (13)
[createdump] Failure took 70ms
``

xPaw avatar Jul 01 '25 07:07 xPaw

I am still unable to reproduce the issue. Could you please share your entire .csproj file?

rcj1 avatar Jul 01 '25 17:07 rcj1

I tested on a dotnet new console project, and added these two lines.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
  </PropertyGroup>

</Project>

xPaw avatar Jul 01 '25 17:07 xPaw

Hello, This is an issue with how the runtime handles singlefile createdump requests. A fix has been initiated in the runtime repository.

rcj1 avatar Jul 03 '25 18:07 rcj1