File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
sdk/core/azure-core/src/http/curl Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff 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: {
You can’t perform that action at this time.
0 commit comments