我有一个.Net 7 API作为后台服务运行,它运行在tanzu kubernetes环境中。我已经安装了dotnet-gcdump,但是当我尝试执行转储(在exec到pod之后)时,使用:
./dotnet-gcdump collect -p 1 -o sample1
我得到一个错误:
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
API的Dockerfile是使用以下脚本在Gitlab CI中动态生成的:
.generate_dockerfile:
script: |
echo "checking dockerfile existence"
if ! [ -e Dockerfile ]; then
echo "dockerfile doesn't exist. Trying to create a new dockerfile from csproj."
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 created"
else
echo "dockerfile exists"
fi
当我运行./dotnet-gcdump --version
时,我得到:
7.0.410101+f9938321xxxxxxxxxxxxxxxxxxxxxxxxxxxx
当我运行./dotnet --info
时,我得到:
.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
我错过了什么?
1条答案
按热度按时间ctehm74n1#
该问题与进程ID有关- i传入了错误的进程ID。
在使用以下命令运行转储之前,必须检查dotnet DLL(主进程)的进程ID:
./dotnet-gcdump ps列出了容器中运行的所有进程,以及它们对应的ID,如下面的示例输出所示: