dotnet-gcdump错误:进程1未运行兼容的.NET运行时

huangapple go评论63阅读模式
英文:

dotnet-gcdump error : Process 1 not running compatible .NET runtime

问题

I'm here to help with the translation:

我有一个在 Tanzu Kubernetes 环境中运行的 .Net 7 API 作为后台服务。我已经安装了 dotnet-gcdump,但是当我尝试执行转储(在进入 pod 后)时,使用:

    ./dotnet-gcdump collect -p 1 -o sample1

我得到一个错误:

    0.0s: 创建类型表刷新任务
    0.0s: [错误] gcdump 过程中出现异常: Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: 进程 1 未运行兼容的 .NET 运行时。
       位置: Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.GetDefaultAddress() 在 /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs:第 282 行
       位置: Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.Connect(TimeSpan timeout) 在 /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs:第 243 行
       位置: Microsoft.Diagnostics.NETCore.Client.IpcClient.SendMessageGetContinuation(IpcEndpoint endpoint, IpcMessage message) 在 /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs:第 40 行
       位置: Microsoft.Diagnostics.NETCore.Client.EventPipeSession.Start(IpcEndpoint endpoint, IEnumerable`1 providers, Boolean requestRundown, Int32 circularBufferMB) 在 /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs:第 34 行
       位置: Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.StartEventPipeSession(IEnumerable`1 providers, Boolean requestRundown, Int32 circularBufferMB) 在 /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs:第 70 行
       位置: Microsoft.Diagnostics.Tools.GCDump.EventPipeSessionController..ctor(Int32 pid, List`1 providers, Boolean requestRundown) 在 /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:第 235 行
       位置: Microsoft.Diagnostics.Tools.GCDump.EventPipeDotNetHeapDumper.DumpFromEventPipe(CancellationToken ct, Int32 processID, MemoryGraph memoryGraph, TextWriter log, Int32 timeout, DotNetHeapInfo dotNetInfo) 在 /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:第 52 行

API 的 Dockerfile 在 Gitlab CI 中动态生成,使用以下脚本:

.generate_dockerfile:

script: |
    echo "检查 Dockerfile 是否存在"
    if ! [ -e Dockerfile ]; then 
    echo "Dockerfile 不存在。尝试从 csproj 创建新的 Dockerfile。"
    pwd
    cd ./src
    echo "$PWD"
    docker_entrypoint=$(grep -m 1 AssemblyName $PWD/*.csproj | sed -r 's/\s*<[^>]*>//g' | sed -r 's/\r$//g').dll
    echo "${docker_entrypoint}"
    cat > Dockerfile << EOF
    FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
    RUN apt-get update && apt-get install -y wget
    RUN wget -O sdk_install.sh https://dot.net/v1/dotnet-install.sh
    RUN chmod 777 sdk_install.sh
    RUN ./sdk_install.sh -c 7.0
    RUN cd /root/.dotnet
    RUN /root/.dotnet/dotnet tool install --global dotnet-gcdump
    RUN echo $PATH
    RUN export ENV PATH="$PATH:/root/.dotnet/tools"
    RUN echo $PATH
    WORKDIR /app
    COPY ./publish .
    
    ENTRYPOINT dotnet $docker_entrypoint
    EOF
    echo "创建 Dockerfile"
    else
    echo "Dockerfile 存在"
    fi

当我运行 `./dotnet-gcdump --version` 时,得到:

    7.0.410101+f9938321xxxxxxxxxxxxxxxxxxxxxxxxxxxx

当我运行 `./dotnet --info` 时,得到:

    .NET SDK:
     版本:   7.0.202
     提交:    6c74320bc3
    
    运行时环境:
     操作系统:     debian
     操作系统版本:  11
     操作系统平台: Linux
     RID:         debian.11-x64
     基础路径:   /root/.dotnet/sdk/7.0.202/
    
    主机:
      版本:      7.0.4
      架构: x64
      提交:       0a396acafe
    
    安装的 .NET SDK:
      7.0.202 [/root/.dotnet/sdk]
    
    安装的 .NET 运行时:
      Microsoft.AspNetCore.App 7.0.4 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 7.0.4 [/root/.dotnet/shared/Microsoft.NETCore.App]
    
    找到的其他架构:
    
    环境变量:
      未设置
    
    global.json 文件:
      未找到

我遗漏了什么?

Please let me know if there's anything else you need!

英文:

I have a .Net 7 API thats runs as a background service and it is running on tanzu kubernetes environment. I have installed dotnet-gcdump but when I try to execute a dump (after exec into pod) using :

./dotnet-gcdump collect -p 1 -o sample1

I am getting an error :

 0.0s: Creating type table flushing task
0.0s: [Error] Exception during gcdump: Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Process 1 not running compatible .NET runtime.
at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.GetDefaultAddress() in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs:line 282
at Microsoft.Diagnostics.NETCore.Client.PidIpcEndpoint.Connect(TimeSpan timeout) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs:line 243
at Microsoft.Diagnostics.NETCore.Client.IpcClient.SendMessageGetContinuation(IpcEndpoint endpoint, IpcMessage message) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs:line 40
at Microsoft.Diagnostics.NETCore.Client.EventPipeSession.Start(IpcEndpoint endpoint, IEnumerable`1 providers, Boolean requestRundown, Int32 circularBufferMB) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs:line 34
at Microsoft.Diagnostics.NETCore.Client.DiagnosticsClient.StartEventPipeSession(IEnumerable`1 providers, Boolean requestRundown, Int32 circularBufferMB) in /_/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs:line 70
at Microsoft.Diagnostics.Tools.GCDump.EventPipeSessionController..ctor(Int32 pid, List`1 providers, Boolean requestRundown) in /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:line 235
at Microsoft.Diagnostics.Tools.GCDump.EventPipeDotNetHeapDumper.DumpFromEventPipe(CancellationToken ct, Int32 processID, MemoryGraph memoryGraph, TextWriter log, Int32 timeout, DotNetHeapInfo dotNetInfo) in /_/src/Tools/dotnet-gcdump/DotNetHeapDump/EventPipeDotNetHeapDumper.cs:line 52

The Dockerfile for the API is generated dynamically in Gitlab CI using the following script :

.generate_dockerfile:
script: |
echo &quot;checking dockerfile existence&quot;
if ! [ -e Dockerfile ]; then 
echo &quot;dockerfile doesn&#39;t exist. Trying to create a new dockerfile from csproj.&quot;
pwd
cd ./src
echo &quot;$PWD&quot;
docker_entrypoint=$(grep -m 1 AssemblyName $PWD/*.csproj | sed -r &#39;s/\s*&lt;[^&gt;]*&gt;//g&#39; | sed -r &#39;s/\r$//g&#39;).dll
echo &quot;${docker_entrypoint}&quot;
cat &gt; Dockerfile &lt;&lt; EOF
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
RUN apt-get update &amp;&amp; apt-get install -y wget
RUN wget -O sdk_install.sh https://dot.net/v1/dotnet-install.sh
RUN chmod 777 sdk_install.sh
RUN ./sdk_install.sh -c 7.0
RUN cd /root/.dotnet
RUN /root/.dotnet/dotnet tool install --global dotnet-gcdump
RUN echo $PATH
RUN export ENV PATH=&quot;$PATH:/root/.dotnet/tools&quot;
RUN echo $PATH
WORKDIR /app
COPY ./publish .
ENTRYPOINT dotnet $docker_entrypoint
EOF
echo &quot;dockerfile created&quot;
else
echo &quot;dockerfile exists&quot;
fi

When I run ./dotnet-gcdump --version I get :

7.0.410101+f9938321xxxxxxxxxxxxxxxxxxxxxxxxxxxx

And when I run ./dotnet --info I get :

.NET SDK:
Version:   7.0.202
Commit:    6c74320bc3
Runtime Environment:
OS Name:     debian
OS Version:  11
OS Platform: Linux
RID:         debian.11-x64
Base Path:   /root/.dotnet/sdk/7.0.202/
Host:
Version:      7.0.4
Architecture: x64
Commit:       0a396acafe
.NET SDKs installed:
7.0.202 [/root/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.4 [/root/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.4 [/root/.dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found

What am I missing ?

答案1

得分: 0

问题出在进程ID上 - 我传递了一个错误的进程ID。

在运行转储之前,您必须检查dotnet DLL(主进程)的进程ID:

cd /root/.dotnet/tools
./dotnet-gcdump ps

./dotnet-gcdump ps列出了容器中运行的所有进程,以及它们对应的ID,就像下面示例输出中的一样:

./dotnet-gcdump ps
6  dotnet  /usr/share/dotnet/dotnet  dotnet MyAPP.Core.MyAPI.dll
英文:

The issue was with the process ID - i was passing in a wrong process ID.

You have to check the process ID of the dotnet DLL (main process) before running the dump with :

cd /root/.dotnet/tools
./dotnet-gcdump ps

./dotnet-gcdump ps lists all the processes running in the container , with their corresponding ID like in the example output below:

./dotnet-gcdump ps
6  dotnet  /usr/share/dotnet/dotnet  dotnet MyAPP.Core.MyAPI.dll 

huangapple
  • 本文由 发表于 2023年4月6日 20:44:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定