[Bug 263458] /usr/bin/pkg sleeps 4 seconds on fetch failures

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 21 Apr 2022 22:11:56 UTC

            Bug ID: 263458
           Summary: /usr/bin/pkg sleeps 4 seconds on fetch failures
           Product: Base System
           Version: 13.0-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: cgull@glup.org

Created attachment 233383
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=233383&action=edit
suggested change to eliminate a sleep(1)

We recently discovered a bug in our `bsdinstall` package-install script; `pkg
query` wasn't being executed with a chroot into the target.  This caused
`/usr/sbin/pkg` to be invoked, it of course tries to bootstrap.  On our
install-CD boot, network has been configured but DNS is broken, so an error is
returned quickly by the resolver.  In this situation `/usr/sbin/pkg` sleeps 1
second before retries, and it retries 4 times.  This multiplied to a 5+ minute
delay in install that went unnoticed for years-- our fault, of course.

This is not an earth-shattering bug and it no longer affects us, but if anyone
else thinks it should be fixed, I've attached a suggested patch that removes
the sleep.  Network error/retry handling is always debatable of course, but it
seems reasonable to take that sleep out.  This program is not that likely to be
misused in ways that hammer servers.  Suggested patch attached, also available
at `https://github.com/cgull/freebsd-src`, branch `pkg-delay`.

This sleep is in code that was copied from `pkg` itself, and
`libpkg/fetch_libfetch.c` contains a corresponding `sleep(1)` also.  But the
code in `pkg` has grown more complex and it seems the path to this particular
case is narrower, I wasn't able to reproduce this in `pkg`.

You are receiving this mail because:
You are the assignee for the bug.