"HTTP call causes SegmentationFault in .NET 10 container on OpenShift (works in .NET 9)"
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
Compiling the following program with dotnet SDK 9 and running it in a dotnet runtime 9 based container on OpenShift works as expected:
```csharp
namespace CertWatch
{
internal static class Program
{
public static void Main(string[] args)
{
Console.Out.WriteLine("Creating client");
HttpClient client = new HttpClient();
Console.Out.WriteLine("Client created");
try
{
var response = client.GetAsync("https://certspotter.com/").Result;
Console.Out.WriteLine($"Response received {response.StatusCode}");
}
catch (Exception ex)
{
Console.Out.WriteLine($"Exception: {ex.Message}");
Console.Out.WriteLine(ex.ToString());
}
finally
{
Console.Out.WriteLine("Leaving");
}
}
}
}
```
```text
Creating client
Client created
Exception: One or more errors occurred. (The proxy tunnel request to proxy 'http://proxy.dc4ca.siemens.de:8080/' failed with status code '403'.")
System.AggregateException: One or more errors occurred. (The proxy tunnel request to proxy 'http://proxy.dc4ca.siemens.de:8080/' failed with status code '403'.")
---> System.Net.Http.HttpRequestException: The proxy tunnel request to proxy 'http://proxy.dc4ca.siemens.de:8080/' failed with status code '403'."
at System.Net.Http.HttpConnectionPool.EstablishProxyTunnelAsync(Boolean async, CancellationToken cancellationToken)
...
Leaving
```
Building the very same program in dotnet 10 and running it in a dotnet 10 container leads to a segmentation fault:
```text
Creating client
Client created
```
This is what I can see in OpenShift logs:
```
The container last terminated with exit code 139 because of Error.
```
This is the dockerfile used:
```
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
LABEL build.commit=$GIT_HASH
LABEL org.opencontainers.image.source="CertWatch"
LABEL org.opencontainers.image.revision=$GIT_HASH
USER $APP_UID
WORKDIR /app
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG BUILD_CONFIGURATION=Release
ARG GIT_HASH
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 \
DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /src
COPY ["sources/CertWatch.csproj", "sources/"]
RUN dotnet restore "./sources/CertWatch.csproj"
COPY ["sources/", "sources/"]
WORKDIR "/src/sources"
RUN dotnet build "./CertWatch.csproj" -c $BUILD_CONFIGURATION -o /app/build /p:GitHash=${GIT_HASH}
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
ARG GIT_HASH
RUN dotnet publish "./CertWatch.csproj" -c $BUILD_CONFIGURATION -r linux-x64 --self-contained true -o /app/publish /p:PublishTrimmed=true /p:UseAppHost=true
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM mcr.microsoft.com/dotnet/runtime-deps:10.0 AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["./CertWatch"]
```
I also tried to build with dotnet 9 sdk and run in dotnet 10 and this also fails.
As reference the pipeline configuration to build the container:
[.gitlab-ci.yml](https://github.com/user-attachments/files/23677058/default.gitlab-ci.yml)
Contributor guide
Assessment
This issue has not been assessed yet.