Releasing OmmConsumer resources in a multithreaded environment C++

I have an HTTP server (cpp-httplib library) that creates and should destroy an instance of the OmmConsumer class when processing a POST request. The library creates 10 threads to handle requests, and it feels like the OmmConsumer instance is not fully destroyed in each of them. Am I doing something wrong or is there a memory leak?

void handle_post_request(const httplib::Request &req, httplib::Response &res){
    try{
        OmmConsumer consumer(OmmConsumerConfig().username("username").host("127.0.0.1:1234"));
        res.set_content("OK", "application/json");
    }
    catch (const std::exception &excp){
        res.set_content("BAD", "application/json");
    }
}

int main(int argc, char *argv[]){
    httplib::Server server;
    auto endpoint = "/test/";
    auto host = "0.0.0.0";
    auto port = 8080;
    try{
        server.Post(endpoint, handle_post_request);
    }
    catch (const std::exception &e){
        return 54;
    }
    server.listen(host, port);
}

Before requests:

1708001491029.png

After requests:

1708001502570.png

Best Answer

  • Gurpreet
    Gurpreet admin
    Answer ✓

    Thank you for the answer, but in my case, I receive HTTP requests with a username for connection and further access verification to the tools, so I can’t create consumers in advance.

    Since, the application is serving over http, and you are snapshoting the data, another option is to skip the http-server part altogether and use the REST interface, which is available in the newer version of RTMDS. You should be able to pass in the username of requesting entity in the REST call as well.

    See this article for more details.

Answers