Bug 235538

Summary: freebsd-update: Try to avoid failing when network is unavailable
Product: Base System Reporter: Ricardo Fraile <r>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Some People CC: cperciva, grahamperrin, lwhsu, r
Priority: --- Keywords: needs-qa
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   
URL: https://github.com/freebsd/freebsd-src/blob/main/usr.sbin/freebsd-update/freebsd-update.sh
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=228397
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235460
Attachments:
Description Flags
Add fetch_check_connection function to freebsd-update none

Description Ricardo Fraile 2019-02-05 18:52:12 UTC
Created attachment 201777 [details]
Add fetch_check_connection function to freebsd-update

Hello,

Running freebsd-update in a system with limited resources (low power cpu and sd storage as disk for example) takes a long time (+5 hours in a RaspberryPi). If we also have a poor network link dependent to a mobile 3G network, is more difficult to complete it properly.

When freebsd-update execute the lines that calls phttpget, if the network is unavailable, it directly fails, throwing away the time spend previously.

There is a workaround tunning phttpget with the HTTP_TIMEOUT environment variable, but it only works before doing the tcp connection. If it can't resolve the dns, it fails ending the execution.

The solution that I include in the patch adds a call to the server previous the phttpget execution, checking if it was ok or not, looping on it waiting 60 seconds until the next try if it fails. If the executions is made from cron, it only loops once and fails.

If you are looking over the upgrade and see that is stuck on that point, you have a chance to fix it, restart the modem, wait until you receive better connectivity or whatever, but it can continue.

In the new function I use the fetch command because is used already on freebsd-update and its part of the base system. Also netcat or telnet can be used, but the environmental variables that can modify the fetch behaviour, like http_proxy, aren't available on those alternatives.

As well, I use for fetch the file latest.ssl because the other file that I found, pub.ssl, is a bit larger. I didn't find any other way to get a dumb file like a readme.txt or similar in the updateN.freebsd.org servers.

I tested it and works as expected.

Thanks,
Comment 1 Graham Perrin 2023-10-06 15:58:06 UTC
Comment on attachment 201777 [details]
Add fetch_check_connection function to freebsd-update

Still applicable: 

% git -C /usr/src/usr.sbin/freebsd-update apply --check --verbose /tmp/235538.patch
Checking patch usr.sbin/freebsd-update/freebsd-update.sh...
Hunk #1 succeeded at 1059 (offset 90 lines).
Hunk #2 succeeded at 1453 (offset 90 lines).
Hunk #3 succeeded at 1506 (offset 90 lines).
Hunk #4 succeeded at 1897 (offset 92 lines).
Hunk #5 succeeded at 1997 (offset 92 lines).
Hunk #6 succeeded at 2032 (offset 92 lines).
%