Skip to content

Commit ac65016

Browse files
committed
Fix CPU spinning when curl_easy_send returns 0 bytes on SSL socket writes
1 parent 183c227 commit ac65016

File tree

1 file changed

+10
-0
lines changed
  • sdk/core/azure-core/src/http/curl

1 file changed

+10
-0
lines changed

sdk/core/azure-core/src/http/curl/curl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ CURLcode CurlConnection::SendBuffer(
624624
// expected to return CURLE_AGAIN (since socket is ready), so, a chuck of data will be uploaded
625625
// and result will be CURLE_OK which breaks the loop. Also, getting other than CURLE_OK or
626626
// CURLE_AGAIN throws.
627+
// NOTE: curl_easy_send() may return CURLE_OK with sentBytesPerRequest == 0 on SSL sockets
628+
// when the socket is not ready for writing. In this case, we add a small delay to prevent
629+
// busy-wait loops and allow the scheduler to release the current quantum.
627630
context.ThrowIfCancelled();
628631
for (CURLcode sendResult = CURLE_AGAIN; sendResult == CURLE_AGAIN;)
629632
{
@@ -637,6 +640,13 @@ CURLcode CurlConnection::SendBuffer(
637640
switch (sendResult)
638641
{
639642
case CURLE_OK: {
643+
if (sentBytesPerRequest == 0)
644+
{
645+
// When curl_easy_send returns CURLE_OK but sends 0 bytes (which can happen on SSL
646+
// sockets), add a small delay to prevent rapid retries that keep the CPU busy
647+
// without making progress. This allows the scheduler to run other threads.
648+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
649+
}
640650
sentBytesTotal += sentBytesPerRequest;
641651
break;
642652
}

0 commit comments

Comments
 (0)