I propose a small diff for pkg_add when using http/https mirrors.
Don't wait 30 seconds for the ftp process to stop when closing
file handler, send SIGHUP immediately after closing the file handler.

Running pkg_add -u neovim (already installed and up to date) I got
those results of bandwidth usage

using mirror https://mirror.one.com/pub/OpenBSD/
62513 kB without diff
9050  kB with diff

using mirror https://ftp.fr.openbsd.org/pub/OpenBSD
6530 kB without diff
6373 kB with diff

The 2500 kB difference between the two mirrors with the diff is
explained by the html directory listing which is different
between servers. mirror.one.com list is 3800 kB while
ftp.fr.openbsd.org only 1387 kB.

I can't explain why but when using mirror.one.com the ftp command will
continuously fetch packages until completion or stop if ftp is killed
after 30 seconds. This extra downloaded data is useless.

I came with the following diff, but maybe the real issue is ftp(1)
not stopping immediately if output is closed?

Index: OpenBSD/PackageRepository.pm
===================================================================
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm,v
retrieving revision 1.171
diff -u -p -r1.171 PackageRepository.pm
--- OpenBSD/PackageRepository.pm        8 Nov 2019 14:50:58 -0000       1.171
+++ OpenBSD/PackageRepository.pm        17 Jun 2020 09:21:41 -0000
@@ -206,12 +206,8 @@ sub close
        my ($self, $object, $hint) = @_;
        close($object->{fh}) if defined $object->{fh};
        if (defined $object->{pid2}) {
-               local $SIG{ALRM} = sub {
-                       kill HUP => $object->{pid2};
-               };
-               alarm(30);
+               kill HUP => $object->{pid2};
                waitpid($object->{pid2}, 0);
-               alarm(0);
        }
        $self->parse_problems($object->{errors}, $hint, $object)
            if defined $object->{errors};

Reply via email to