dict: avoid busy-loop in sendf() when the socket is not writable - #22576
thomas-chauchefoin-tob wants to merge 1 commit into
Conversation
Curl_xfer_send() reports CURLE_AGAIN as a successful zero-byte send, so the retry loop spun at 100% CPU and ignored the timeout when the peer stopped draining. Wait for writability and check the remaining time between retries.
|
An ancient corner of curl's protocols, basically from 1999. The "real" solution would be to format a send buffer and never return |
|
I can try to implement that, but it would have to wait for a few weeks. Should I keep this PR around or drop it? |
|
Keep the PR, I think. We can merge this and then someone needs to find the time to do the non-blocking solution. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a busy-loop in the DICT protocol’s sendf() helper when Curl_xfer_send() reports a would-block condition as CURLE_OK with a zero-byte write. The updated loop now waits for socket writability and re-checks the remaining overall transfer time between retries, aligning DICT behavior with the existing approach used by gopher_do().
Changes:
- Add timeout-aware retry behavior to
sendf()by checkingCurl_timeleft_ms()between partial/blocked sends. - Avoid 100% CPU spinning by waiting for socket writability via
SOCKET_WRITABLE()when progress stalls. - Add the necessary internal headers (
connect.h,select.h) to support the new logic.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Yeah, I figure this is still a small step forward even if it can be improved further! |
|
Thanks! |
Curl_xfer_send()reportsCURLE_AGAINas a successful zero-byte send, so the retry loop spun at 100% CPU and ignored the timeout when the peer stopped draining. Wait for writability and check the remaining time between retries, likegopher_do()already does.Found while investigating the timeout in coverage collection for the
curl_fuzzer_dictfuzzer on OSS-Fuzz.