Repository navigation
fix event-based connection shutdown and add a test for it - #22304
GrahamCampbell wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in libcurl’s event/socket-action API where connections in graceful shutdown could stop being progressed (leading to leaked fds/memory), and adds a focused event-driven client + HTTP test to prevent regressions.
Changes:
- Ensure connection filter pollset adjustment is performed when a connection has entered shutdown, so shutdown sockets remain registered with the app’s socket callback.
- Fix shutdown timer arming logic so
EXPIRE_SHUTDOWNis scheduled correctly. - Add a new event-driven libtest client (
cli_ev_download) and a new pytest case (test_19_08) to validate shutdown sockets stay supervised until shutdown completes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/libtest/Makefile.inc | Adds the new event-driven test client to the libtest build. |
| tests/libtest/cli_ev_download.c | New strict socket-action loop client to reproduce/verify shutdown socket supervision. |
| tests/http/test_19_shutdown.py | Adds a new pytest that asserts shutdown sockets are watched and fully drained. |
| lib/cshutdn.c | Fixes next shutdown-expire scheduling so shutdown timeouts can fire. |
| lib/cfilters.c | Makes pollset adjustment consult shutdown state so shutdown sockets stay registered. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Analysis of PR #22304 at 7b701945: Test ../../tests/http/test_32_ftps_vsftpd.py::TestFtpsVsFTPD::test_32_06_shutdown_download 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 |
7b70194 to
d880a2a
Compare
|
@icing about your busy loop fix and this modification is the intention to adjust both if the one socket is connected but the other isn't, or one is shutting down but the other isn't, because I mean for example why is not applied per filter if only that filter meets requirements, like for example what about this: for(i = 0; (i < 2) && !result && conn; ++i) {
if(ps->n && conn->cfilter[i] &&
(!Curl_conn_is_connected(conn, i) ||
conn_shutdown_started(conn, i))) {
result = Curl_conn_cf_adjust_pollset(conn->cfilter[i], data, ps);
}
}because otherwise both can adjusted depending on the check of one? maybe I misunderstand |
d880a2a to
22200cb
Compare
22200cb to
9a2aed0
Compare
icing
left a comment
There was a problem hiding this comment.
Nice work, adding the test client and case!
In curl 8.21 the progress handling of shutdowns became brokwn as the connections sockets were no longer added to the pollset. Fix-by: pszemus refs curl#22282
865e47c to
3939466
Compare
|
Thanks |
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
- Adjust pollset during connection shutdown. - Separate the FIRSTSOCKET and SECONDSOCKET check so that one being in connect or shutdown no longer adds poll events for the other. - Fix shutdown state evaluation (as detailed below). - Add a unit test for Curl_conn_adjust_pollset. - Add a client for event testing. - Test that shutdown sockets stay with the socket callback until done. The pollset predicate now reads the connection's own shutdown state rather than going through data->conn, and the EXPIRE_SHUTDOWN arming in cshutdn_perform() works again: next_expire_ms started at 0 and could never be set, so a peer that never sends a close_notify would still park its connection forever, timeout or not. Reported-by: [email protected] Fixes curl#22282 Closes curl#22304 Backport notes: - unit2606.c: the release's struct Curl_cftype still has do_close, so the test filter sets Curl_cf_def_close. - Added test2606 and unit2606.c to the release's test lists. - Dropped the new cli_ev_download.c client and its pytest; the fix does not need them. (cherry picked from commit 820c014)
This builds on @icing's fix from #22284, with @pszemus's analysis in #22282, and adds a follow-up commit with two small additional things I noticed. The pollset predicate now reads the connection's own shutdown state rather than going through
data->conn, and theEXPIRE_SHUTDOWNarming incshutdn_perform()works again:next_expire_msstarted at 0 and could never be set, so a peer that never sends a close_notify would still park its connection forever, timeout or not.I also wanted this covered by a test, which turned out to be fun: the curl tool cannot show the bug at all, since it runs the multi's admin handle eagerly enough to rescue parked connections. So the new
cli_ev_downloadclient drives transfers through a strictcurl_multi_socket_action()loop like a real event application would, andtest_19_08checks that shutdown sockets stay with the socket callback until done. It fails on master without the fix and passes with it.