Bug 263458 - /usr/bin/pkg sleeps 4 seconds on fetch failures
Summary: /usr/bin/pkg sleeps 4 seconds on fetch failures
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-21 22:11 UTC by cgull
Modified: 2022-10-12 09:03 UTC (History)
0 users

See Also:


Attachments
suggested change to eliminate a sleep(1) (744 bytes, application/mbox)
2022-04-21 22:11 UTC, cgull
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description cgull 2022-04-21 22:11:56 UTC
Created attachment 233383 [details]
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`.
Comment 1 cgull 2022-04-21 22:26:08 UTC
Github issue mentioning the potential problem in `pkg`:  https://github.com/freebsd/pkg/issues/2038#issue-1211610701
Comment 2 commit-hook freebsd_committer freebsd_triage 2022-07-28 15:56:30 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=60b92ba9323c2dd249ba3a3349b207c2d0b9d212

commit 60b92ba9323c2dd249ba3a3349b207c2d0b9d212
Author:     John Hood <jhood@niksun.com>
AuthorDate: 2022-04-21 21:39:14 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-07-28 15:55:13 +0000

    /usr/sbin/pkg: don't sleep on fetch failure

    PR:     263458

 usr.sbin/pkg/pkg.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-10-12 09:03:14 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3cb757615f26c5a486b9dde1ba5c3df478ccfe60

commit 3cb757615f26c5a486b9dde1ba5c3df478ccfe60
Author:     John Hood <jhood@niksun.com>
AuthorDate: 2022-04-21 21:39:14 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-12 09:01:56 +0000

    /usr/sbin/pkg: don't sleep on fetch failure

    PR:     263458
    (cherry picked from commit 60b92ba9323c2dd249ba3a3349b207c2d0b9d212)

 usr.sbin/pkg/pkg.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2022-10-12 09:03:15 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=fdf6f6babe6169261dd396c9bf966ab8a82a7c64

commit fdf6f6babe6169261dd396c9bf966ab8a82a7c64
Author:     John Hood <jhood@niksun.com>
AuthorDate: 2022-04-21 21:39:14 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-12 09:01:44 +0000

    /usr/sbin/pkg: don't sleep on fetch failure

    PR:     263458
    (cherry picked from commit 60b92ba9323c2dd249ba3a3349b207c2d0b9d212)

 usr.sbin/pkg/pkg.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)