I'm using the Parallel Patterns Library to run several http clients in parallel in this manner:
concurrency::parallel_for_each(begin(queries), end(queries), [&](const std::pair<std::string, std::string> &p){
try
{
sf::Http http("some_host_name");
sf::Http::Request request("some_path_name" + p.second);
auto response = http.sendRequest(request, sf::seconds(30));
if (response.getBody().find(found_substring) != std::string::npos)
{
results.push(p.first);
}
// some debug info gathering stuff omitted for brevity
}
catch (const std::exception &e)
{
// error handling code omitted for brevity
}
});
Note that both the "queries" and "results" are concurrency safe containers from the PPL.
The problem is that sometimes the above code gets stuck (it doesn't crash, just doesn't work properly). I've done some error checking and I've observed the following:
The problem is related to the SFML http client, which returns error code 1001 and times out. Once the problem occurs, the same thread will continue reporting error 1001 from its http clients. The problem takes some time to appear, usually after several thousand queries have been processed successfully.
Any tips on how I can diagnose and solve the problem?