grafana / pyroscope-dotnet

Dotnet profiler
Apache License 2.0
25 stars 6 forks source link

Pyroscope libraries resulting in segmentation fault #20

Closed sentient-glare closed 1 year ago

sentient-glare commented 1 year ago

Following the instructions for the dotnet beta integration. I am trying to profile an ASPNET application with Pyroscope.

Dockerfile below - this is largely copied from a Microsoft example. When I build and run this, the container exits with a 139 code (seg fault).

Things I've tried:

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine3.16 AS build
WORKDIR /sln

# Copy project file and restore
COPY "TestApp.Api.csproj" "."
RUN dotnet restore TestApp.Api.csproj

# Copy the actual source code
COPY "." "."

# Build and publish the app
RUN dotnet publish "TestApp.Api.csproj" -c Release -o /app/publish --self-contained false --no-restore

#FINAL image
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine3.16
WORKDIR /app
COPY --from=build /app/publish .

# Set up Pyroscope profiling
RUN apk update && apk add gcompat
RUN wget -P /lib/ https://github.com/pyroscope-io/pyroscope-dotnet/releases/download/v0.7.0/Pyroscope.Linux.ApiWrapper.x64.so
RUN wget -P /lib/ https://github.com/pyroscope-io/pyroscope-dotnet/releases/download/v0.7.0/Pyroscope.Profiler.Native.so
ENV PYROSCOPE_APPLICATION_NAME=test.dotnet.app
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope-route:80
ENV PYROSCOPE_PROFILING_ENABLED=1
ENV CORECLR_ENABLE_PROFILING=1
ENV CORECLR_PROFILER={BD1A650D-AC5D-4896-B64F-D6FA25D6B26A}
ENV CORECLR_PROFILER_PATH=/lib/Pyroscope.Profiler.Native.so
ENV LD_PRELOAD=/lib/Pyroscope.Linux.ApiWrapper.x64.so

ENTRYPOINT ["dotnet", "TestApp.Api.dll"]
korniltsev commented 1 year ago

I believe we will need to build separate binaries for alpine/musl

sentient-glare commented 1 year ago

Gotcha - using Alpine isn't a requirement for me but I got similar results with Debian and Ubuntu

korniltsev commented 1 year ago

oops. I will look into it.

korniltsev commented 1 year ago

@sentient-glare I tried to reproduce the crash on glibc based base image and could not reproduce

Here is what I tried: https://github.com/pyroscope-io/pyroscope/blob/fix/crash_dotnet_example/examples/dotnet/web-new/Dockerfile

I wonder what is the difference with your setup on debian base image. Is there any chance you could share a stacktrace of segmentation fault? or even better a coredump? or even better full self-contained example crashing(not alpine)?

Btw, what is your host OS and architecture?

sentient-glare commented 1 year ago

Sorry for the wait on this. I tried out a Dockerfile similar to yours and it worked fine for me, I think I didn't track my local testing all that well and it was using Alpine images that was the issue all along and/or was doing some funky stuff with the libraries 😢 the debian images all work for me now. thanks for the help!