From 82e87ffb7c336fda8952bce024b714bff4abd31f Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 20 Feb 2025 19:42:10 -0500 Subject: [PATCH] Fix #2068 --- httplib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/httplib.h b/httplib.h index 6296e2d..6d91a43 100644 --- a/httplib.h +++ b/httplib.h @@ -7333,6 +7333,16 @@ inline ClientImpl::ClientImpl(const std::string &host, int port, client_cert_path_(client_cert_path), client_key_path_(client_key_path) {} inline ClientImpl::~ClientImpl() { + // Wait until all the requests in flight are handled. + size_t retry_count = 10; + while (retry_count-- > 0) { + { + std::lock_guard guard(socket_mutex_); + if (socket_requests_in_flight_ == 0) { break; } + } + std::this_thread::sleep_for(std::chrono::microseconds{1}); + } + std::lock_guard guard(socket_mutex_); shutdown_socket(socket_); close_socket(socket_);