Skip to content

Commit 82e87ff

Browse files
committed
Fix #2068
1 parent 22d90c2 commit 82e87ff

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

httplib.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7333,6 +7333,16 @@ inline ClientImpl::ClientImpl(const std::string &host, int port,
73337333
client_cert_path_(client_cert_path), client_key_path_(client_key_path) {}
73347334

73357335
inline ClientImpl::~ClientImpl() {
7336+
// Wait until all the requests in flight are handled.
7337+
size_t retry_count = 10;
7338+
while (retry_count-- > 0) {
7339+
{
7340+
std::lock_guard<std::mutex> guard(socket_mutex_);
7341+
if (socket_requests_in_flight_ == 0) { break; }
7342+
}
7343+
std::this_thread::sleep_for(std::chrono::microseconds{1});
7344+
}
7345+
73367346
std::lock_guard<std::mutex> guard(socket_mutex_);
73377347
shutdown_socket(socket_);
73387348
close_socket(socket_);

0 commit comments

Comments
 (0)