Skip to content

pingpong: schedule server response timeouts for the socket API - #23246

Closed
KurodaKayn wants to merge 2 commits into
curl:masterfrom
KurodaKayn:fix/pingpong-response-timeout
Closed

KurodaKayn wants to merge 2 commits into
curl:masterfrom
KurodaKayn:fix/pingpong-response-timeout

Conversation

@KurodaKayn

@KurodaKayn KurodaKayn commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

A silent FTP, IMAP, POP3 or SMTP server can leave transfers driven by
curl_multi_socket_action() waiting past CURLOPT_SERVER_RESPONSE_TIMEOUT_MS
because the response deadline is checked but never scheduled.

Register the remaining response time with a dedicated timer in the
nonblocking pingpong state machine.

Add a representative FTP regression test (2330) using the existing
event-driven client. It sets a 1-second response timeout and a separate
3-second test deadline that does not drive libcurl's timers. The test
fails before the fix and passes afterward. IMAP, POP3 and SMTP share
the same nonblocking pingpong path.

Validation on macOS with a Debug build and TLS disabled:

  • The original reproducer returns CURLE_OPERATION_TIMEDOUT after about
    1 second for all four protocols.
  • Test 2330 and existing tests 100, 800, 851 and 900 pass.
  • Silent and delayed greetings time out at the expected deadlines.
  • checksrc and git diff --check pass.

Fixes #23025

The nonblocking pingpong state machine checks the response deadline
without scheduling a timer. A silent server can therefore leave
curl_multi_socket_action() waiting indefinitely.

Register the remaining time with a dedicated expiration ID so the
event loop wakes up to check the response deadline.

Add regression tests for FTP, IMAP, POP3 and SMTP using the existing
event-driven client with an independent test deadline.

Fixes curl#23025
@github-actions github-actions Bot added the tests label Oct 3, 2026

@vszakats vszakats left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong reason to test this in 4 individual test? Could they perhaps be merged into a single test or perhaps tested with one selected protocol only? (They seem to be all using the same lower-level fix)

@KurodaKayn

Copy link
Copy Markdown
Contributor Author

Is there a strong reason to test this in 4 individual test? Could they perhaps be merged into a single test or perhaps tested with one selected protocol only? (They seem to be all using the same lower-level fix)

I originally added one for each protocol because the issue report covered FTP, IMAP, POP3, SMTP, and I verified the reproducer with all four.
However, You're right, all four nonblocking paths call the same functions where this fix lives.
The tests are therefore mostly duplicates.

I agree that one representative protocol test is sufficient for the regression. I will keep the FTP case and remove the other three

The FTP, IMAP, POP3 and SMTP cases all exercise the same pingpong\nstate machine and timer path. Keep one representative protocol case to\ncover the regression without duplicating identical tests.

Follow-up to 596f663

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The shared four-protocol timeout change lacks the reported regression coverage beyond FTP.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Schedules pingpong response deadlines so socket-driven transfers can time out when servers remain silent, addressing #23025.

Changes:

  • Adds a dedicated server-response timer and trace name.
  • Extends the event-driven test client with configurable deadlines.
  • Adds an FTP regression test and runner support.
File Description
tests/​runner.pm Routes cli_ tools through libtests.
tests/​libtest/​cli_ev_download.c Adds timeout options and deadline cleanup.
tests/​data/​test2330 Tests FTP response timeouts.
tests/​data/​Makefile.am Registers test2330.
lib/​urldata.h Defines the response timer identifier.
lib/​pingpong.c Schedules nonblocking response deadlines.
lib/​curl_trc.c Names the timer in traces.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/data/Makefile.am Resolved
@bagder

bagder commented Oct 7, 2026

Copy link
Copy Markdown
Member

Thanks!

@bagder bagder closed this in b32baab Oct 7, 2026
@vszakats

vszakats commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Seeing the test added by this PR failing in torture tests without c-ares on Linux and with threaded-resolver on macOS. Meaning this test fails torture with default build settings:

test 2330 [FTP server response timeout with the socket action API]
 78 functions found, but only fail 25 (32.05%)
** MEMORY FAILURE
Leak detected: memory still allocated: 3083 bytes
At 13400b608, there is 3056 bytes.
 allocated by /Users/runner/work/curl/curl/lib/url.c:457
At 600002bf8158, there is 27 bytes.
 allocated by /Users/runner/work/curl/curl/lib/curlx/strdup.c:87
LIMIT /Users/runner/work/curl/curl/lib/multi_ev.c:94 calloc reached memlimit
 2330: torture FAILED: function number 18 in test.
 invoke with "-t18" to repeat this single case.

macOS: https://github.com/curl/curl/actions/runs/42739522174/job/129576860210?pr=23869#step:17:1457
Linux: https://github.com/curl/curl/actions/runs/42739521997/job/129576860241?pr=23869#step:45:3215

→ PR #23872

vszakats added a commit that referenced this pull request Nov 10, 2026
Seen in test 2330 torture with c-ares not enabled, or threaded-resolved
not disabled.

Fixing:
```
test 2330 [FTP server response timeout with the socket action API]
 76 functions found, but only fail 25 (32.89%)
** MEMORY FAILURE
Leak detected: memory still allocated: 3056 bytes
At 5c4ca478c9e8, there is 3056 bytes.
 allocated by /home/runner/work/curl/curl/lib/url.c:457
LIMIT /home/runner/work/curl/curl/lib/curlx/strdup.c:87 malloc reached memlimit
 2330: torture FAILED: function number 14 in test.
 invoke with "-t14" to repeat this single case.
```
Linux: https://github.com/curl/curl/actions/runs/42739521997/job/129576860241?pr=23869#step:45:3215
macOS: https://github.com/curl/curl/actions/runs/42739522174/job/129576860210?pr=23869#step:17:1457

Bug: #23246 (comment)
Bug: #23869 (comment)
Follow-up to b32baab #23246
Follow-up to 820c014 #22304
Cherry-picked from #23869

Closes #23872
@KurodaKayn

Copy link
Copy Markdown
Contributor Author

Seeing the test added by this PR failing in torture tests without c-ares on Linux and with threaded-resolver on macOS. Meaning this test fails torture with default build settings:

Thanks for catching this and fixing the error-path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

curl_multi_socket_action() can wait indefinitely past CURLOPT_SERVER_RESPONSE_TIMEOUT

5 participants