How does beast boost async http client works in c++11 when multiple simultaneous requests are made in a single threaded asynchronous system?
USE CASE:
I want to send multiple simultaneous asynchronous requests and I am creating new http client for each request. When response of any request is received then I am calling a callback function which deletes the client after 1 sec of the response received to avoid any memory leaks. But it appears that the system/ code hangs in between after some random number of simulatneous http requests even though I create a new client object for each request. Does beast boost use some shared resource as this pause looks like system is in an infinite deadlock. PS: I also tried commenting this delete block but then also system behaves the same.
Below are the specifications for the boost and compiler version:
boost: stable 1.68.0
BOOST_BEAST_VERSION 181
clang -v
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
void sendHttpRequest(){
HttpClient *client = new HttpClient();
deleteClient = [this,client]{
int timeout = 1;
boost::asio::deadline_timer *clientDeleteTimer = new boost::asio::deadline_timer( *this->context);
clientDeleteTimer->expires_from_now(boost::posix_time::seconds(timeout));
clientDeleteTimer->async_wait([client,this,clientDeleteTimer](const boost::system::error_code &ec){
if(ec == boost::asio::error::operation_aborted){
std::cout<<" Operation aborted\n"<<std::flush;
return;
}
else{
delete client;
}
delete clientDeleteTimer;
};
callback = [] {
std::cout<<"Response recieved successfully\n"<<std::flush;
deleteClient();
};
errback = [] {
std::cout<<"Response not recieved \n"<<std::flush;
deleteClient();
};
client.sendPostRequest(request, callback , errback);
}
this function above is a wrapper function which will be called for each request and internally will create new http async client and delete that client object after 1 sec of response / error is recieved (basically the request has been processed).