If fetch receives SIGINFO after the server stopped sending data it goes into a loop and starts eating 100% cpu even continuing after the connection to the server has been closed. It's my impression that fetch.c relies on fread() to modify errno in a way it doesn't. The following patch prevents the cpu-eating loop, but fetch still fails to properly save the received data: commit 2131ebe654b5d9b48a715ea1955941b9d3e89f4d Author: Fabian Keil <fk@fabiankeil.de> Date: Sat Oct 15 22:12:54 2011 +0200 Manually set errno to 0 before calling fread() in fetch(). The fact that this makes a difference seems to suggest that fread() doesn't behave like fetch expects it to. diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index 9862276..18c6d5a 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -636,6 +636,7 @@ fetch(char *URL, const char *path) stat_end(&xs); siginfo = 0; } + errno = 0; /* XXX: Why does this have an effect? */ if ((size = fread(buf, 1, size, f)) == 0) { if (ferror(f) && errno == EINTR && !sigint) clearerr(f); How-To-Repeat: Run a "webserver" like this one: (printf "HTTP/1.1 200 Okay\r\nConnection: close\r\nContent-Length: 10\r\n\r\n0123456789"; sleep 5) | nc -l 81 Use fetch to request a resource, send SIGINFO before the sleep time is up and watch it eating cpu time without doing anything useful: fk@r500 ~ $fetch http://127.0.0.1:81/ fetch.out 0% of 10 B 0 Bps load: 0.80 cmd: fetch 3698 [select] 0.70r 0.00u 0.00s 0% 2464k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps load: 0.83 cmd: fetch 3698 [runnable] 12.32r 0.64u 10.96s 70% 2504k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps load: 0.87 cmd: fetch 3698 [running] 24.50r 1.22u 22.54s 96% 2504k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps load: 0.91 cmd: fetch 3698 [running] 52.70r 2.84u 49.10s 100% 2504k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps load: 0.92 cmd: fetch 3698 [running] 59.60r 3.26u 55.55s 100% 2504k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps^C fetch: transfer interrupted With the errno patch one gets: fk@r500 /tank/scratch $fetch http://127.0.0.1:81/ fetch.out 0% of 10 B 0 Bps load: 0.74 cmd: fetch 3812 [select] 0.69r 0.00u 0.00s 0% 2464k fetch.out 0% of 10 B 0 Bps fetch.out 0% of 10 B 0 Bps fetch: http://127.0.0.1:81/: No error: 0 and no output file even though all the data has been delivered. If SIGINFO isn't sent, the resource is properly received.
This is very similar to/exactly the problem I fixed in libfetch a little while ago. Indeed, I can't reproduce it on my laptop running CURRENT. See r230307 and bin/153240. -Mark
Mark Johnston <markjdb@gmail.com> wrote: > This is very similar to/exactly the problem I fixed in libfetch a > little while ago. Indeed, I can't reproduce it on my laptop running > CURRENT. See r230307 and bin/153240. I noticed r230307 and while I assumed that it might fix it, I didn't get around to testing it yet. Thanks for the reminder (and the fix of course). I can confirm that the problem is no longer reproducible. As far a I'm concerned the PR can be closed. Fabian
State Changed From-To: open->closed Apparently this has already been fixed.