Repository navigation
connect: bound post-connect blocking connects by their own start - #23528
zipadoodlez wants to merge 2 commits into
Conversation
Before this change, curl had no connect timeout after MSTATE_DO. A blocking connect could then wait forever. The FTPS data connection TLS handshake is one example. Curl_conn_connect() now records the first call for each socket. It uses that time for the blocking connect timeout after MSTATE_DO. When the filter chain is discarded, curl clears the time. A new data connection then gets a new timeout. The change also moves the connect timeout default and the expired timeout rule into one helper. timeleft_now_ms() uses the same helper. Co-authored-by: Rhino <195818135+1rhino2@users.noreply.github.com>
410c774 to
9ce9d89
Compare
|
Analysis of PR #23528 at 9ce9d890: Test ../../tests/http/test_02_download.py::TestDownload::test_02_06_download_many_parallel[h3] failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 2 different CI jobs (the link just goes to one of them). Generated by Testclutch |
|
ran this branch against the stall fixture i used for the report (implicit tls, 150 delayed 1.5s, data socket accepted and never answered) and the lib side does what the description says. the trace has the first connect call on the data socket at .341 and the connect timeout at .343 two seconds later, 2.06s total. im fine with this landing instead of #23506. the test is the problem tho. 1792 fails here 5 out of 5 runs with time_total between 3.44 and 3.53, and the fix is not what eats that time. the control connection through stunnel takes 1.2 to 1.3s to come up on this box (time_appconnect 1.25 and 1.34 in two runs) before EPSV is even sent, and the traced run still shows the timeout firing 2.00s after the first data connect call. the postcheck counts that setup time inside time_total, so a slow runner fails a working fix. something like the CM quiche red is a 502 from nghttpx on stream 41 of the parallel h3 test with curl exiting 0, not this change. |
The test server has a new STALLDATA mode. It accepts the data connection and sends no data. The test waits one second before the 150 response. Then the data TLS handshake stalls. The test uses --max-time 5 as a safety bound. A postcheck reads time_total and time_appconnect. It subtracts the control connection's TLS setup and fails when the remaining time is 2.8 seconds or more. The fix stops at the 2 second connect timeout. The original patch starts the timer after the 150 response. It stops at 3 seconds. A total timeout stops at 5 seconds.
9ce9d89 to
b9db11d
Compare
|
good catch on the test. I implemented your recommendation. agreed on the quiche red not being related to this pr. |
There was a problem hiding this comment.
🟢 Approval recommended
The timeout calculation and timestamp lifecycle are consistent, with targeted regression coverage and no unresolved blocking findings.
No open issues 🎉
What changed in this PR
This PR bounds blocking connections after the normal connect phase using each socket’s original connection start time. This prevents stalled FTPS data handshakes from waiting indefinitely and includes time spent waiting for the server’s 150 response.
Changes:
- Track per-socket connection start times and reset them when filter chains are discarded.
- Share connect-timeout calculation between normal and post-connect timeout checks.
- Add an FTPS regression test with a silent data connection and elapsed-time validation.
| File | Description |
|---|---|
| tests/test1792.pl | Validate elapsed time after subtracting control-connection setup. |
| tests/Makefile.am | Include the new postcheck script in distribution files. |
| tests/ftpserver.pl | Add STALLDATA mode to hold data connections silent. |
| tests/data/test1792 | Test that the data connect timeout includes the 150-response wait. |
| tests/data/Makefile.am | Register test 1792. |
| lib/urldata.h | Store per-socket connection start timestamps. |
| lib/connect.c | Apply start-based timeout bounds to blocking connections. |
| lib/cfilters.c | Reset timestamp validity when discarding socket filter chains. |
Review effort: Balanced
|
Thanks! |
Supersedes #23506.
This PR has two commits: the fix and the test.
Problem
curl drops the connect timeout when a transfer reaches MSTATE_DO. A
blocking connect can then wait forever. The TLS handshake of an FTPS
data connection is one example.
The original patch in #23506 stops the hang. But it starts the timer
when the blocking wait starts.
CURLOPT_CONNECTTIMEOUT.mdsays theconnection phase includes the name resolve and all protocol handshakes
until the connection is established. For a passive FTPS data connection,
the TCP connect and the wait for the 150 response happen before the
blocking wait. The original patch does not count them.
Change
Curl_conn_connect()first sees each socket.MSTATE_DO.data connection then gets a new timeout.
one helper.
timeleft_now_ms()uses the same helper.Test
STALLDATAis a new mode in the FTP test server. It accepts the dataconnection and sends no data. Test 1792 waits one second before the 150
response. Then the data TLS handshake stalls.
The test uses
--max-time 5as a safety bound. A postcheck readstime_total. It fails when the value is 2.8 seconds or more. Thisrejects a total-timeout exit and a timer that starts after the 150
response.
The test uses
--max-time 5as a safety bound. A postcheck readstime_totalandtime_appconnect, subtracts the control connectionsetup, and fails when the remaining time is 2.8 seconds or more. This
rejects a total-timeout exit and a timer that starts after the 150
response, without counting a slow control connection.
Results
FTP/FTPS tests 400, 401, 402, 405, 1112, 1790, and 1792 pass.
Credit
The original patch is by @1rhino2 in #23506.
Open question
Should the timer start at the first
Curl_conn_connect()call for thesocket? That call covers the DNS, TCP, and handshake work in the filter
chain. It does not cover FTP setup before that call. A protocol-level
timestamp is needed for an earlier start.