pact-net icon indicating copy to clipboard operation
pact-net copied to clipboard

Azure Pipeline Ubuntu 18.04 Unable to load shared library 'pact_ffi' or one of its dependencies

Open aimashevrallyup opened this issue 2 years ago • 6 comments

Pact 4.0.0 NET 5

In Azure Pipeline ubuntu 18.04 agent throws this error

System.DllNotFoundException : Unable to load shared library 'pact_ffi' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libpact_ffi: cannot open shared object file: No such file or directory

aimashevrallyup avatar Jun 17 '22 12:06 aimashevrallyup

Could you provide some more info such as the OS architecture? It could be that the container is 32bit whereas only 64bit is supported

adamrodger avatar Jun 17 '22 16:06 adamrodger

I've recreated this locally, like this:

docker run --rm -it ubuntu:18.04

# inside the container...

# install .Net
apt update && apt install -y wget
wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt update && apt install -y dotnet-sdk-6.0

# create a sample project
mkdir /app
cd /app
dotnet new xunit
dotnet add package PactNet --version 4.0.0

# create a sample test
cat > UnitTest1.cs <<EOF
namespace app;
using System.Net;
using PactNet;
public class UnitTest1
{
    private readonly IPactBuilderV3 _pactBuilder;

    public UnitTest1()
    {
        var pact = Pact.V3("Something API Consumer", "Something API");
        _pactBuilder = pact.UsingNativeBackend();
    }

    [Fact]
    public async Task Test()
    {
        // Arrange
        _pactBuilder
            .UponReceiving("a request")
                .WithRequest(HttpMethod.Get, "/")
            .WillRespond()
                .WithStatus(HttpStatusCode.OK);

        await _pactBuilder.VerifyAsync(async ctx =>
        {
            var client = new HttpClient { BaseAddress = ctx.MockServerUri };

            var response = await client.GetAsync("/");

            response.EnsureSuccessStatusCode();
        });
    }
}
EOF

# run the test
dotnet test

This produces the error:

Test run for /app/bin/Debug/net6.0/app.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.38]     app.UnitTest1.Test [FAIL]
  Failed app.UnitTest1.Test [1 ms]
  Error Message:
   System.DllNotFoundException : Unable to load shared library 'pact_ffi' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libpact_ffi: cannot open shared object file: No such file or directory
  Stack Trace:
     at PactNet.Interop.NativeInterop.LogToBuffer(LevelFilter levelFilter)
   at PactNet.PactExtensions.InitialiseLogging(PactLogLevel level)
   at PactNet.PactExtensions.InitialiseServer(MockServer server, IPact pact, PactSpecification version)
   at PactNet.PactExtensions.UsingNativeBackend(IPactV3 pact, Nullable`1 port, IPAddress host)
   at app.UnitTest1..ctor() in /app/UnitTest1.cs:line 11
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)

Failed!  - Failed:     1, Passed:     0, Skipped:     0, Total:     1, Duration: < 1 ms - /app/bin/Debug/net6.0/app.dll (net6.0)

The process indicates that it's running 64bit fortunately.

adamrodger avatar Jun 19 '22 15:06 adamrodger

If I try the exact same thing on Ubuntu 22.04 (so the exact same script as above but replacing any 18.04 strings with 22.04) then it works fine, so this is a problem specific to 18.04:

Test run for /app/bin/Debug/net6.0/app.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Mock server logs:

[INFO][pact_mock_server::hyper_server] Received request HTTP Request ( method: GET, path: /, query: None, headers: Some({"host": ["127.0.0.1:40599"]}), body: Empty )
[INFO][pact_matching] comparing to expected HTTP Request ( method: GET, path: /, query: None, headers: None, body: Missing )
[INFO][pact_mock_server::hyper_server] Request matched, sending response HTTP Response ( status: 200, headers: None, body: Missing )


Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: < 1 ms - /app/bin/Debug/net6.0/app.dll (net6.0)

adamrodger avatar Jun 19 '22 15:06 adamrodger

This is caused by a missing glibc version on Ubuntu 18.04. Running ldd bin/Debug/net6.0/runtimes/linux-x64/native/libpact_ffi.so shows the difference. So this is a problem with the FFI library itself, not with PactNet. I'll raise a linked defect against the FFI.

In 22.04:

        linux-vdso.so.1 (0x00007ffcfad62000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc21e876000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc21e871000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc21e78a000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc21e785000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc21e55d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc21f9fe000)

in 18.04:

bin/Debug/net6.0/runtimes/linux-x64/native/libpact_ffi.so: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by bin/Debug/net6.0/runtimes/linux-x64/native/libpact_ffi.so)
bin/Debug/net6.0/runtimes/linux-x64/native/libpact_ffi.so: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by bin/Debug/net6.0/runtimes/linux-x64/native/libpact_ffi.so)
        linux-vdso.so.1 (0x00007fff635f6000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f612634e000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f612612f000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6125d91000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6125b8d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f612579c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f61276ca000)

adamrodger avatar Jun 19 '22 16:06 adamrodger

@aimashevrallyup all I can suggest for now is upgrading to Ubuntu 20.04 or newer. They have the required version of glibc that the FFI library needs so it should work on there. The glibc version on 18.04 isn't high enough though unfortunately.

adamrodger avatar Jun 19 '22 16:06 adamrodger

@adamrodger tyvm!

p.s. ubuntu 20.04 can also be used as 22.04

aimashevrallyup avatar Jun 19 '22 21:06 aimashevrallyup

The pact ffi library has just been updated to work with glibc 2.24: https://github.com/pact-foundation/pact-reference/releases/tag/libpact_ffi-v0.3.8. It should now support Debian 9, Ubuntu 18.04 and RHEL 8 too. Would it be possible to pick that up for Pact-Net and do a new release with that?

omajid avatar Aug 19 '22 02:08 omajid

We are also having issues with PACT.NET on RHEL 8 with similar error messages as described in this ticket. We get the following error: /lib64/libc.so.6: version `GLIBC_2.29' not found (required by... RHEL 8 has glibc version 2.28. We would also be interested in @omajid PR being picked up by Pact-Net.

abebehailu avatar Aug 22 '22 13:08 abebehailu