cpp-redis / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform
MIT License
713 stars 198 forks source link

Thread deadlock caused by a large number of asynchronous requests #78

Closed jinsoojeong closed 3 years ago

jinsoojeong commented 3 years ago

OS : Windows Visual Studio : VS 2019 -> C++17 compiler version : cpprestsdk 2.10 -> 2019 Release

In our project, we are using CppRestSDK to make requests to the API server. However, I have seen thread deadlocks for a large number of API requests. In order to perform a completely asynchronous operation, we made the API request and then receive an operation through .then(), and we do not use the .wait() function.

image

/// ----- ex)

for () // -> count loop test {

http_client client(U("url"));
client.request(U("GET")).then([](http_response resp){
  wcout << U("STATUS : ") << resp.status_code() << endl;
  wcout << "content-type : " << resp.headers().content_type() << endl;

  resp.extract_string(true).then([](string_t sBoby){
      wcout << sBoby << endl;
  });
})

}

/// -----

We have repeatedly requested a large number of API requests in the way we tested, and if approximately 1000 or more requests are executed within one code block, You have noticed that the asynchronous thread enters an infinite lock state.

Please let me know if you have a suitable solution for this, or if you have any guidelines for API calls.

Here's what we think about.

  1. Execute .wait() until the thread receives the result at the same time as the request. (The thread that executes the request is managed asynchronously.)
  2. Request by controlling the number of requests that can be called at one time.
jinsoojeong commented 3 years ago

sorry