[dotnet] Possible Missing Core Package for System.Net.Http.Native
Hi there,
I'm new to distroless, but I may have found an issue with the dotnet build that I'd like some extra eyes on. After getting a few projects built up I ended up including one of my larger projects with multiple dependencies. One of these included the AWSSDK.Core which has a heavy reliance on System.Net.Http.HttpClient.
Any distroless container that references the AWSSDK.Core breaks at runtime with the following error:
2018-03-07 01:41:43.8449|ERROR|Program.Main|Processor Died. System.AggregateException: One or more errors occurred. (The type initializer for 'System.Net.Http.CurlHandler' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Net.Http.Native': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at Interop.Http.GetSslVersionDescription()
at Interop.HttpInitializer..cctor()
--- End of inner exception stack trace ---
at Interop.Http..cctor()
--- End of inner exception stack trace ---
at Interop.Http.GetSupportedFeatures()
at System.Net.Http.CurlHandler..cctor()
--- End of inner exception stack trace ---
at System.Net.Http.CurlHandler..ctor()
at System.Net.Http.HttpClientHandler..ctor()
at Amazon.Runtime.HttpRequestMessageFactory.CreateHttpClient(IClientConfig clientConfig)
at Amazon.Runtime.HttpRequestMessageFactory.CreateHttpClientCache(IClientConfig clientConfig)
at Amazon.Runtime.HttpRequestMessageFactory.CreateHttpRequest(Uri requestUri)
at Amazon.Runtime.Internal.HttpHandler`1.CreateWebRequest(IRequestContext requestContext)
at Amazon.Runtime.Internal.HttpHandler`1.<InvokeAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
/// This is repeated a few times ///
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at Messaging.Providers.AWSSQSMessagingClient.ReceiveMessage[T](String queueName, Int32 timeout) in /opt/my/project/Providers/AWSSQSMessagingClient.cs:line 71
Other apps seemed to work just fine, but this was the first that involved a network request so I created a quick project to test a theory. I built the sample found at [https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client], applied the following docker file:
robby@Vierge ~/projects/httpclient
$ cat Dockerfile
# Pull down a recent base image of the dotnet sdk
FROM microsoft/dotnet:2.0.5-sdk-2.1.4 AS build-env
# Setup our environment
COPY . /opt/httpclient
WORKDIR /opt/httpclient
# Build our App
RUN dotnet restore
RUN dotnet publish -c Release -r linux-x64
RUN ls -alh bin/Release/netcoreapp2.0/linux-x64/publish
# Bootstrap the Distroless Image Layer
## Using the latest image
FROM gdc.io/distroless/dotnet
## Using the version released last month
# FROM gcr.io/distroless/dotnet@sha256:165939f644e70c294b9907ca94b2a51f7ad5621d468f105f5080b24ebdaafbc7
# Copy The SDC App to the distroless layer
COPY --from=build-env /opt/httpclient/bin/Release/netcoreapp2.0/linux-x64/publish /opt/httpclient
# Finally, execute our container
WORKDIR /opt/httpclient
ENTRYPOINT [ "dotnet", "httpclient.dll" ]
Which built just fine using docker build -t httpclient:distoless ., but running it with docker run -t httpclient:distoless yielded the familiar:
Unhandled Exception: System.TypeInitializationException: The type initializer for 'HttpClientSample.Program' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Net.Http.Native': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)
at Interop.Http.GetSslVersionDescription()
at Interop.HttpInitializer..cctor()
--- End of inner exception stack trace ---
at Interop.Http..cctor()
--- End of inner exception stack trace ---
at Interop.Http.GetSupportedFeatures()
at System.Net.Http.CurlHandler..cctor()
--- End of inner exception stack trace ---
at System.Net.Http.CurlHandler..ctor()
at System.Net.Http.HttpClientHandler..ctor()
at System.Net.Http.HttpClient..ctor()
at HttpClientSample.Program..cctor() in /opt/httpclient/Program.cs:line 19
--- End of inner exception stack trace ---
at HttpClientSample.Program.<RunAsync>d__7.MoveNext() in /opt/httpclient/Program.cs:line 74
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at HttpClientSample.Program.Main() in /opt/httpclient/Program.cs:line 69
Reverting my build back to distroless-less(?), allows both of these containers to run without issue. But also increases the image size from 128M to 2.4G and is generally distasteful in every form.
The only information that I have is that curl is not installed correctly in the underlying image which is something that I cannot include in the Self Contained Deployment of the application as it's a prerequisite of running dotnet which appears to be satisfied but according to some quick research, it appears that this error is thrown due to an improper build (but I'm not sure how much to attribute to this).
Going distroless is not a showstopper for me at this time, but I would like to leverage this approach if possible. My gut says that something in the distroless/dotnet image needs attention but I'm at a loss as to what. Let me know if I can help in any way. I've attached my sample
httpclient project as a gzip tarball (which likely doesn't work but should at least yield an error message than a stack trace) and the logs can be found in logs/*.log.
Cheers, Robby
hi-
I'm going to look into this a bit more this coming week and will attempt the repro you've got.
As youv'e noted, the dotnet distroless image would use the files from runtime-deps image for dotnet here
something like:
to
- https://github.com/GoogleCloudPlatform/distroless/blob/master/dotnet/BUILD#L7
(the dotnet base build uses
//ccimage itself as a base
just i've noticed is dotnet image uses libssl1.0.2
while our baseline has libssl1.1 (which is higher)
i don't know if it means anything at all but i'll try to parse through the difference next week incase something else is missing.
still investigating but for ref, here is what System.Net.Http.Native.so
on
FROM microsoft/dotnet:2.0.0-runtimeuses
root@559924aeca8a:/app/bin/Release/netcoreapp2.0/linux-x64/publish# ldd System.Net.Http.Native.so
linux-vdso.so.1 (0x00007ffdbb77a000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007fa4b3fd6000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa4b3c54000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa4b3950000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa4b3739000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa4b339a000)
libnghttp2.so.14 => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007fa4b3174000)
libidn2.so.0 => /usr/lib/x86_64-linux-gnu/libidn2.so.0 (0x00007fa4b2f52000)
librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007fa4b2d35000)
libssh2.so.1 => /usr/lib/x86_64-linux-gnu/libssh2.so.1 (0x00007fa4b2b09000)
libpsl.so.5 => /usr/lib/x86_64-linux-gnu/libpsl.so.5 (0x00007fa4b28fb000)
libssl.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 (0x00007fa4b2692000)
libcrypto.so.1.0.2 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 (0x00007fa4b222e000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007fa4b1fe3000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007fa4b1d09000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007fa4b1ad6000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007fa4b18d2000)
liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007fa4b16c3000)
libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007fa4b1472000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fa4b1258000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa4b103b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa4b445a000)
libunistring.so.0 => /usr/lib/x86_64-linux-gnu/libunistring.so.0 (0x00007fa4b0d24000)
libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007fa4b098b000)
libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007fa4b0756000)
libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007fa4b051f000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fa4b029c000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007fa4aff8c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa4afd88000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007fa4afb7c000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007fa4af978000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fa4af761000)
libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007fa4af546000)
libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007fa4af2e1000)
libidn.so.11 => /lib/x86_64-linux-gnu/libidn.so.11 (0x00007fa4af0ad000)
libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007fa4aee9a000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007fa4aec86000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fa4aea7d000)
@mattmoor , what would be the way to debug potential dependency like this?
this is what i'm trying
docker run -it gcr.io/distroless/dotnet:debug
shoudn't i see the .so files i declared here in this path
/usr/lib/x86_64-linux-gnu/
(i understood the debug variant to have the same library but with shell access/busybox)
btw: issue # 169 updated libssl
Looks like the full curl package is missing...
The distrollss image used microsoft/dotnet:2.0-runtime-deps but the actual dotnet runtime add in curl itself:
At the moment, if i used the dotnet:debug image,
FROM microsoft/dotnet:2.0.0-sdk AS build-env
ADD . /app
WORKDIR /app
RUN dotnet restore -r linux-x64
RUN dotnet publish -c Release -r linux-x64
#FROM microsoft/dotnet:2.0.0-runtime
FROM gcr.io/distroless/dotnet:debug
#FROM bazel/dotnet:dotnet
#FROM bazel/dotnet:debug
WORKDIR /app
COPY --from=build-env /app /app/
#CMD ["bin/Release/netcoreapp2.0/linux-x64/publish/httpclient"]
docker build -t test docker run -it test
cd /app/bin/Release/netcoreapp2.0/linux-x64/publish create ldd (its just a script copied mine from my laptop in; had to change gives:
/app/bin/Release/netcoreapp2.0/linux-x64/publish # /busybox/sh ldd System.Net.Http.Native.so
linux-vdso.so.1 (0x00007ffe1cd5c000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f187c512000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f187c190000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f187be8c000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f187bc75000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f187b8d6000)
libnghttp2.so.14 => not found
libidn2.so.0 => not found
librtmp.so.1 => not found
libssh2.so.1 => not found
libpsl.so.5 => not found
libssl.so.1.0.2 => not found
libcrypto.so.1.0.2 => not found
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f187b68b000)
libkrb5.so.3 => not found
libk5crypto.so.3 => not found
libcom_err.so.2 => not found
liblber-2.4.so.2 => not found
libldap_r-2.4.so.2 => not found
libz.so.1 => not found
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f187b46e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f187c996000)
libkrb5.so.3 => not found
libk5crypto.so.3 => not found
libcom_err.so.2 => not found
libkrb5support.so.0 => not found
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f187b26a000)
libkeyutils.so.1 => not found
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f187b053000)
So far, i added in libnghttp2 by editing locally:
adding
#dotnet
"libcurl3",
"libgssapi-krb5-2",
"libicu57",
"liblttng-ust0",
"libunwind8",
"libuuid1",
"liblzma5",
"libnghttp2-14",
ten in
- dotnet/BUILD adding
debs = [
packages["libcurl3"],
packages["libgssapi-krb5-2"],
packages["libicu57"],
packages["liblttng-ust0"],
packages["libunwind8"],
packages["libuuid1"],
packages["liblzma5"],
packages["libnghttp2-14"],
],
build the image locally and specifying FROM bazel/dotnet:debug:
bazel build dotnet:debug bazel run dotnet:debug
atleast shows nghttp is found:
/app/bin/Release/netcoreapp2.0/linux-x64/publish # /busybox/sh ldd System.Net.Http.Native.so
linux-vdso.so.1 (0x00007ffcb7a26000)
libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007f97abbfe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f97ab87c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f97ab578000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f97ab361000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f97aafc2000)
libnghttp2.so.14 => /usr/lib/x86_64-linux-gnu/libnghttp2.so.14 (0x00007f97aad9c000)
So search for missing packages an add them in similarly
I'll work through all the missing bits shortly
atleast the following worked set was enough for the app cited in this is issue to startup (!).
I'll dig around to find out what all 'curl' installs comprehensively vs me reverse engineering..
- WORKSPACE
#dotnet
"libcurl3",
"libgssapi-krb5-2",
"libicu57",
"liblttng-ust0",
"libunwind8",
"libuuid1",
"liblzma5",
"libnghttp2-14",
"libidn2-0",
"librtmp1",
"libssh2-1",
"libpsl5",
"libkrb5-3",
"libk5crypto3",
"libcomerr2",
"libldap-2.4-2",
"libkrb5support0",
"libkeyutils1",
"libunistring0",
"libgnutls30",
"libhogweed4",
"libnettle6",
"libgmp10",
"libgcrypt20",
"libsasl2-2",
"libp11-kit0",
"libidn11",
"libtasn1-6",
"libgpg-error0",
- dotnet/BUILD
debs = [
packages["libcurl3"],
packages["libgssapi-krb5-2"],
packages["libicu57"],
packages["liblttng-ust0"],
packages["libunwind8"],
packages["libuuid1"],
packages["liblzma5"],
packages["libnghttp2-14"],
packages["libidn2-0"],
packages["librtmp1"],
packages["libssh2-1"],
packages["libpsl5"],
packages["libssl1.0.2"],
packages["libkrb5-3"],
packages["libk5crypto3"],
packages["libcomerr2"],
packages["libldap-2.4-2"],
packages["libkrb5support0"],
packages["libkeyutils1"],
packages["libunistring0"],
packages["libgnutls30"],
packages["libhogweed4"],
packages["libnettle6"],
packages["libgmp10"],
packages["libgcrypt20"],
packages["libsasl2-2"],
packages["zlib1g"],
packages["libp11-kit0"],
packages["libidn11"],
packages["libtasn1-6"],
packages["libgpg-error0"],
packages["libffi6"],
],
Interesting finding but seems logical from past experiences with curl. Appreciate the investigation on this. Please let me know if I can assist in any way.
if you want to give it a shot early, you can build from the commit here.....you'll need to install
$ git clone https://github.com/GoogleCloudPlatform/distroless.git
$ git fetch origin pull/175/head:test_branch
$ git checkout test_branch
build:
$ bazel build dotnet:dotnet
.............................
INFO: Analysed target //dotnet:dotnet (32 packages loaded).
INFO: Found 1 target...
INFO: From ImageLayer dotnet/dotnet-layer.tar:
Duplicate file in archive: ./var/lib/dpkg/status.d/libldap, picking first occurrence
Duplicate file in archive: ./var/lib/dpkg/status.d/libsasl2, picking first occurrence
Target //dotnet:dotnet up-to-date:
bazel-bin/dotnet/dotnet-layer.tar
INFO: Elapsed time: 36.142s, Critical Path: 11.09s
INFO: Build completed successfully, 11 total actions
generate the image
$ bazel run dotnet:dotnet
INFO: Analysed target //dotnet:dotnet (0 packages loaded).
INFO: Found 1 target...
Target //dotnet:dotnet up-to-date:
bazel-bin/dotnet/dotnet-layer.tar
INFO: Elapsed time: 0.571s, Critical Path: 0.03s
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/dotnet/dotnet
Loaded image ID: sha256:37a349e3ea9c875151e98abe92573b29a0b24e729e8f455c2f053fbf6a0111ea
Tagging 37a349e3ea9c875151e98abe92573b29a0b24e729e8f455c2f053fbf6a0111ea as bazel/dotnet:dotnet
so now you should have the 'distroless' image locally: bazel/dotnet:dotnet:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 7abc2db7e84d 45 seconds ago 491MB
debian 8 5dd74d62fab8 2 weeks ago 123MB
bazel/dotnet dotnet 37a349e3ea9c 48 years ago 134MB