Hi I am getting segmentation fault when i am execu...
# libpact_ffi-users
p
Hi I am getting segmentation fault when i am executing
pactffi_verifier_broker_source_with_selectors
Copy code
2024-04-11T15:03:22.613421Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked
2024-04-11T15:03:22.613463Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked
2024-04-11T15:03:22.613480Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_add_provider_transport FFI function invoked
2024-04-11T15:03:22.613495Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_state FFI function invoked
2024-04-11T15:03:22.613532Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked
2024-04-11T15:03:22.613546Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_publish_options FFI function invoked
broker_url Variable: <http://localhost:9292/>
broker_username Variable: pact_workshop
broker_password Variable: pact_workshop
enable_pending Variable: 1
branch Variable: develop
consumer_version_selectors Variable: {}
consumer_version_selectors_len Variable: 0
2024-04-11T15:03:22.613621Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked
2024-04-11T15:03:22.613640Z DEBUG ThreadId(10) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_execute FFI function invoked
2024-04-11T15:03:22.613651Z DEBUG ThreadId(10) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(<http://localhost:9292/>, provider_name='animal_service', enable_pending=true, include_wip_since=None, provider_tags=[], provider_branch=Some("develop"), consumer_version_selectors='[], auth=User(pact_workshop, pact*********)')
2024-04-11T15:03:22.749605Z  INFO ThreadId(10) pact_verifier::pact_broker: Fetching path '/' from pact broker

make: *** [Makefile:13: test] Segmentation fault (core dumped)
Any pointers as to what might be causing this or how should i debug this?
j
How are you executing? Are you using a specific language wrapper, or do you have your own wrapper? A seg fault clearly is not ideal, but from the logs you have, it would appear that seg fault is happening immediately after trying to fetch
/
, but before it even gets a chance to receive a response. Perhaps there's something malformated within the selectors?
r
Also, we have had segfaults with Alpine Linux, are you running it with that? Enabling trace level logs will help
p
Surprisingly, when I enabled trace logs, the segfault appear to be gone 😅 confused dog
Its not working on ubuntu systems, but working on my local (mac arm64) 😕
j
Do you have a minimal example you can share with us to replicate the issue? That would be immensely helpful.
p
Copy code
/* niftest.c */
#include <pact.h>
#include <string.h>
#include <stdio.h>


int test_pactffi() {
    printf("Verification Start--------------------\n");

    char *name = "animal_service";
    char *scheme = "http";
    char *host = "localhost";
    int port = 8080;
    char *path = "/";
    char *version = "default";
    char *branch = "develop";
    char *broker_url = "<http://localhost:9292/>";
    // OSS pact broker docker image: pactfoundation/pact-broker
    char *broker_username = "pact_workshop";
    char *broker_password = "pact_workshop";
    int enable_pending = 1;
    char *consumer_version_selectors = "{}";
    int consumer_version_selectors_len = 0;
    char *protocol = "http";

    
    char *state_path = "<http://localhost:8080/pactStateChange>";

    struct VerifierHandle *verifierhandle;
    verifierhandle = pactffi_verifier_new_for_application(name, version);
    pactffi_verifier_set_provider_info(verifierhandle, name, scheme, host, port, path);
    pactffi_verifier_add_provider_transport(verifierhandle, protocol, port, path, scheme);

    if (state_path[0] != '\0')
    {
        pactffi_verifier_set_provider_state(verifierhandle, state_path, 0, 1);
    }
    pactffi_verifier_set_verification_options(verifierhandle, 0, 5000),
    pactffi_verifier_set_publish_options(verifierhandle, version, NULL, NULL, -1, branch);
    pactffi_verifier_broker_source_with_selectors(verifierhandle, broker_url, broker_username, broker_password, NULL, enable_pending, NULL, NULL, -1, branch, consumer_version_selectors, consumer_version_selectors_len, NULL, -1);
    setenv("PACT_DO_NOT_TRACK", "true", 1);
    int output = pactffi_verifier_execute(verifierhandle);
    pactffi_verifier_shutdown(verifierhandle);

    printf("Verification End------------------------\n");


    return output;
}

int main() {
    // Function call
    pactffi_logger_init();
    pactffi_logger_attach_sink("stdout", 5);
    pactffi_logger_apply();
    int output = test_pactffi();

    printf("Output is ------ %d\n", output);
    return 0;
}
Also i am trying to run the above code by following the below steps: Step 1: Get the shared library .so
Copy code
gcc -O2 -Wmissing-prototypes -Wall -shared -o /home/ranjan/work/pact_erlang/libpact_ffi.so /home/ranjan/work/pact_erlang/c_src/pactffi_test.c -I/home/ranjan/work/pact_erlang/c_src/include /home/ranjan/work/pact_erlang/priv/libpact_ffi-linux-x86_64.a
Step 2: Compile the pactffi_test.c
Copy code
gcc -c -I./c_src/include ./c_src/pactffi_test.c
Step 3: Get the executable to run:
Copy code
gcc -O2 -Wmissing-prototypes -Wall -shared -o pactffi_test -L. pactffi_test.o -lpact_ffi
I am still getting segmentation fault, even after I remove the pact ffi calls from my c file.
Update: I was able to execute the above c code separately. I think there is something wrong in the erlang-c communication that might be causing the seg fault here. back to the drawing board
j
Thanks for the details! I'll take a look on Monday. The face you're getting seg fails even after you remove the FFI calls would indicate the fault is not in the FFI, which is a good first step. Some care must be taken when crossing language boundaries, and it's possible an assumption made in one language isn't being followed in the other. If it is more specifically with Erlang or Pact Erlang, you might get better/more specific help from that channel.