-
Notifications
You must be signed in to change notification settings - Fork 305
Open
Description
Issue: HTTP(S)ClientEx future never resolves if server endpoint is down, timeout is ignored
Hello,
First of all, thanks for this great library!
I'm having an issue with the asynchronous HTTP(S) client, specifically with HTTPSClientEx and SendGetRequest().
Description
When I start the Asio service correctly, everything works as expected if the server endpoint (API) is up and reachable.
However, if the server endpoint is not running (e.g., "127.0.0.1 refused to connect"), the request does not fail after the specified timeout, and std::future.get() never returns – the thread stays blocked indefinitely.
I specifically want to use HTTPSClientEx because it returns std::future as a synchronization primitive, which fits my use case perfectly.
Minimal reproducible example
#include "server/http/http_client.h"
#include "string/string_utils.h"
#include <iostream>
int main(int argc, char** argv)
{
// HTTP server address
std::string address = "127.0.0.1";
std::cout << "HTTP server address: " << address << std::endl;
std::cout << std::endl;
// Create a new Asio service
auto service = std::make_shared<CppServer::Asio::Service>();
// Start the Asio service
std::cout << "Asio service starting...";
service->Start();
std::cout << "Done!" << std::endl;
// Create a new HTTP client
auto client = std::make_shared<CppServer::HTTP::HTTPClientEx>(service, address, 13000);
try{
std::string url = "/api/v1/keys/3/status";
std::cout << "Sending Request with 5sec timeout." << std::endl;
auto future = client->SendGetRequest(url, CppCommon::Timespan::seconds(5));
std::cout << "waiting for response..." << std::endl;
auto response = future.get(); // <--- Hanging ?!
std::cout << response << std::endl;
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
// Stop the Asio service
std::cout << "Asio service stopping...";
service->Stop();
std::cout << "Done!" << std::endl;
return 0;
}Please check the screenshot below:

Metadata
Metadata
Assignees
Labels
No labels