Repository navigation
FTP: bound the active-mode connect to 5 s - #1068
Conversation
The active-mode data connection set a 5 s socket timeout before connect() so that a dead PORT address would fail fast, but lwIP's blocking connect ignores socket timeouts and waits for TCP to give up, about 18 s with the session blocked. It now connects without blocking and waits at most 5 s in select() for the outcome. STOR wrote whatever each recv() returned, often a single TCP segment, so the file system copied every write through its sector buffer. The 8 KB buffer is now filled before it is written, so the middle of each write is whole sectors. A stalled or aborted upload still keeps every byte that arrived, and an empty upload still creates no file. The FTP protocol is unchanged. The new host test target/pc/linux/ftpd runs ftpd.cc's data connection against loopback sockets; it is part of make host_tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chrisgleissner
left a comment
There was a problem hiding this comment.
@JC-000 thanks for this. The bounded connect looks right to me: non-blocking connect, select on the write set, SO_ERROR for the result, and blocking mode restored on every path. Your U64E and C64U timings (about 18 s down to 5 s) are the evidence for it, since a Linux host honours SO_SNDTIMEO on connect and cannot show the defect.
Requesting one change: the whole-buffer STOR writes are a separate change from #1057. The description reports +13% on the U64E and 0% on the C64U and makes no throughput claim. Please move that part into its own PR, or drop it, so this one stays a focused fix for the connect timeout. The nine stub headers and the STOR tests would move with it.
Happy to merge the connect fix as soon as that is split.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The whole-buffer STOR writes are a separate change from the active-mode connect bound (GideonZ#1057), so they move to their own change. This removes the receivefile() change and the four STOR cases from the host test. The two connect cases stay, and so does the host test harness, which they need to build ftpd.cc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The connect fix is shown by the hardware measurement, since a Linux host honours the socket timeout that lwIP ignores, so the host test could not show the defect. The harness goes with the STOR change that it was written for. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the review. I split it as you asked: a new commit takes the whole-buffer STOR change out, along with its tests and the host test harness and stub headers, so this PR is now the connect fix alone (only The connect fix has no host test now. A Linux host honours the socket timeout on connect and lwIP does not, so only the hardware timings show the defect (about 18 s down to 5 s on both devices, in the description). Written with Claude Opus and Claude Sonnet in Claude Code. |
Makefile host_tests: drop the stale ftpd line (this PR removed the ftpd host test) and keep master's new socketdma line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chrisgleissner
left a comment
There was a problem hiding this comment.
Thanks. The STOR change is out, so this is the connect fix alone (only ftpd.cc). The non-blocking connect, select on the write set, SO_ERROR check and restored blocking mode on every path look right. Approving.
|
I'm assigning this to myself. I'm investigating whether it is merge ready by running the standard E2E profile locally on an Ultimate 64 Elite and an Ultimate II+L, with this PR combined with the other approved bug fixes, and comparing against master. I'll report the result here. |
|
Test result for the batch this PR is part of (#1043, #1064, #1065, #1066, #1068, #1070). Firmware: upstream master
|
Brings in GideonZ#1043 (send the whole HTTP request, give up on a stalled server), GideonZ#1064, GideonZ#1065 and GideonZ#1068, which this change is stacked on. Conflicts, all from this branch carrying the pre-merge form of GideonZ#1043: - build.yml, test_http_target.cc, http_request.cc, send_all.h, send_all_test.cpp, test_http_target/Makefile: kept this branch's side, which is upstream's plus this PR's own change. - io/network/tests/Makefile: took upstream's (only target order differed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges the updated fix/uci-abort-reset-deferral (890ef6d), which carries upstream master with GideonZ#1043, GideonZ#1064, GideonZ#1065 and GideonZ#1068 merged in. Conflict: software/io/network/tests/Makefile, only in the target order (this branch had send-all after sys-arch-red, upstream before it). Kept upstream's order and added the network-target target and variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #1057
Problem
In FTP active mode the server connects back to the client's
PORTaddress. If that address does not answer, the connect blocks the FTP control task for the full TCP connect timeout (~18 s) before failing, even though the code intends a 5 s bound. During that time the control connection is unresponsive.FTPDataConnection::connect_to(software/network/ftpd.cc) sets the socket'sSO_RCVTIMEO/SO_SNDTIMEOto 5 s and then calls blockingconnect(). lwIP's blockingconnect()ignores those timeouts and waits for TCP to give up on its own, so the 5 s bound has no effect.What changed and why
The blocking connect is replaced by a non-blocking connect plus a bounded
select()(ftp_connect_bounded): put the socket in non-blocking mode, start the connect, wait at most 5 s for it to become writable, checkSO_ERROR, then restore blocking mode. An unreachable data address now fails in 5 s.Products. Runs on the Ultimate 64, Ultimate 64 Elite II, C64 Ultimate and the Ultimate-II cartridges (U2+, U2+L). Tested on the Ultimate 64 Elite and the C64 Ultimate.
How I tested it
There is no host test: a Linux host honours
SO_SNDTIMEOon connect and lwIP does not, so a host run cannot show the defect. The fix rests on the hardware measurement below.Hardware.
Active connect to a dead address, then LIST:
Standard profile (
./run-tests --profile standard), red = master, green = a build carrying this landing set of fixes (this change included), report frompython3 tools/e2e_report.py:iec-partition-config: it stops at a key-send step because the upstream test's REST backend has noF2key alias (rest_backend.py:556), a test-side limitation, not an app difference.iec-partition-config, here at a "menu screen unavailable" step that also fails on master, so it is not from these changes.Soaks pass on both devices: mount-cache-leak, listener-soak, network-connection.
Untested
Written with Claude Opus and Claude Sonnet in Claude Code.