nats-io / nats.c

A C client for NATS
Apache License 2.0
384 stars 134 forks source link

Errno Variable getting set after calling js_PullSubscribe method from nats.c client #795

Open sudojha opened 1 week ago

sudojha commented 1 week ago

Observed behavior

Once a connection is made to the nats server and a pull subscription is created using the js_PullSubscribe method, the errno (provided by errno.h) gets set to code 84 (EOVERFLOW : Value too large to be stored in data type).

Expected behavior

errno should not be set to a value post js_PullSubscribe call.

Server and client version

I have compiled the nats c client from source code (main branch) and using it in my c project. Server version: 2.10.18

Host environment

Host env: MacOs Sonoma 14.4

Steps to reproduce

Here's a sample code to reproduce the above behaviour:

#include <iostream>
extern "C" {
#include <nats/nats.h>
}

int main()
{
    natsStatus status;
    natsConnection *conn = nullptr;

    // Initialize the NATS client
    status = natsConnection_ConnectTo(&conn, "nats://localhost:4222");
    if (status != NATS_OK) {
        std::cerr << "Error connecting to NATS: " << natsStatus_GetText(status) << std::endl;
        return 1;
    }

    natsSubscription *sub = NULL;
    jsSubOptions opts;
    status = jsSubOptions_Init(&opts);
    if(status != NATS_OK) {
        perror(natsStatus_GetText(status));
    }
    opts.Consumer = "pull_consumer";
    jsCtx *jetStreamContext = nullptr;
    natsConnection_JetStream(&jetStreamContext,conn,NULL);
    jsSubOptions subOpts;
    status = jsSubOptions_Init(&subOpts);
    if(status != NATS_OK) {
        perror(natsStatus_GetText(status));
    }
    opts.Consumer = "pull_consumer";
    subOpts.Config.AckPolicy = js_AckExplicit;
    natsSubscription *ns = nullptr;
    perror("error before js_PullSubscribe");
    status = js_PullSubscribe(&ns,jetStreamContext,"foo","pull_consumer",NULL,&subOpts,nullptr);
    if (status != NATS_OK) {
        perror("error while pull subscription");
    }
    perror("error after js_PullSubscribe");

    // Clean up
    natsSubscription_Destroy(ns);
    natsConnection_Destroy(conn);
    nats_Close();

    return 0;
}

This consistently results in the following output:

error before js_PullSubscribe: Resource temporarily unavailable
error after js_PullSubscribe: Value too large to be stored in data type

Process finished with exit code 0

While it has no direct impact on the functioning of the library, it could be an indicator of some underlying issue.