Skip to content

Commit a3d2cbc

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

File tree

1 file changed

+12
-1
lines changed
  • sdk/core/azure-core/src/http/curl

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
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,7 +640,15 @@ CURLcode CurlConnection::SendBuffer(
637640
switch (sendResult)
638641
{
639642
case CURLE_OK: {
640-
sentBytesTotal += sentBytesPerRequest;
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+
} else {
650+
sentBytesTotal += sentBytesPerRequest;
651+
}
641652
break;
642653
}
643654
case CURLE_AGAIN: {

0 commit comments

Comments
 (0)