Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apt_dpkg: retry on HTTP 429 'Too Many Requests' #319

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bdrung
Copy link
Collaborator

@bdrung bdrung commented Apr 17, 2024

Running the system tests on different releases in parallel can cause some tests of test_packaging_apt_dpkg fail:

__________________ test_install_packages_dependencies[deb822] __________________
[...]
apport/packaging_impl/apt_dpkg.py:1326: SystemExit
----------------------------- Captured stderr call -----------------------------
ERROR: Package download error, try again later: Failed to fetch http://ddebs.ubuntu.com/pool/main/p/pcre2/libpcre2-8-0-dbgsym_10.39-3build1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/libs/libselinux/libselinux1-dbgsym_3.3-1build2_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

Retry package download if HTTP 429 'Too Many Requests' errors can be found in the apt.cache.FetchFailedException error. The download is retries with an exponential backoff and giving up after around one hour.

Copy link

codecov bot commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.02%. Comparing base (75a7fd9) to head (0b2ebff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #319      +/-   ##
==========================================
+ Coverage   83.00%   83.02%   +0.02%     
==========================================
  Files          99       99              
  Lines       20333    20357      +24     
  Branches     3212     3216       +4     
==========================================
+ Hits        16877    16901      +24     
+ Misses       2936     2935       -1     
- Partials      520      521       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdrung
Copy link
Collaborator Author

bdrung commented Apr 17, 2024

The retry does not seem to work as intended: https://github.com/bdrung/apport/actions/runs/8718363097/job/23915454500

@bdrung
Copy link
Collaborator Author

bdrung commented Apr 17, 2024

We also have failing apt updates:

self = <apport.packaging_impl.apt_dpkg.__AptDpkgPackageInfo object at 0x7f32cca86490>
aptroot = '/tmp/tmpdkc5aafi/cache/Foonux 22.04/apt'
apt_dir = '/tmp/tmpdkc5aafi/config/Foonux 22.04'
fetchProgress = <apt.progress.base.AcquireProgress object at 0x7f32bc36be50>
distro_name = 'ubuntu', release_codename = 'jammy', origins = None
arch = 'amd64'

    def _sandbox_cache(
        self,
        aptroot,
        apt_dir,
        fetchProgress,
        distro_name,
        release_codename,
        origins,
        arch,
    ):  # pylint: disable=too-many-arguments
        """Build apt sandbox and return apt.Cache(rootdir=) (initialized
        lazily).
    
        Clear the package selection on subsequent calls.
        """
        if not self._sandbox_apt_cache or arch != self._sandbox_apt_cache_arch:
            self._clear_apt_cache()
            self._build_apt_sandbox(
                aptroot, apt_dir, distro_name, release_codename, origins
            )
            rootdir = os.path.abspath(aptroot)
            self._sandbox_apt_cache = apt.Cache(rootdir=rootdir)
            self._sandbox_apt_cache_arch = arch
            try:
                # We don't need to update this multiple times.
                self._sandbox_apt_cache.update(fetchProgress)
            except apt.cache.FetchFailedException as error:
>               raise SystemError(str(error)) from error
E               SystemError: W:Download is performed unsandboxed as root as file '/tmp/tmpdkc5aafi/cache/Foonux 22.04/apt/var/lib/apt/lists/partial/archive.ubuntu.com_ubuntu_dists_jammy_InRelease' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied), E:Failed to fetch http://ddebs.ubuntu.com/dists/jammy/main/binary-amd64/Packages.gz  429  Too Many Requests [IP: 185.125.190.18 80], E:Failed to fetch http://ddebs.ubuntu.com/dists/jammy-updates/main/binary-amd64/Packages.gz  429  Too Many Requests [IP: 185.125.190.18 80], E:Some index files failed to download. They have been ignored, or old ones used instead.

See https://github.com/bdrung/apport/actions/runs/8718363097/job/23915453469

Copy link
Contributor

@schopin-pro schopin-pro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One small nitpick.

apt_cache.fetch_archives(fetcher=fetcher)
break
except apt.cache.FetchFailedException as error:
if backoff <= 3600 and "Too Many Requests" in str(error):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this is misleading wrt the git log

While it is technically correct because the git log says "around 1h" so if the next delay is 4096s we've already waited 4095s (yay maths), backoff is still a derivation of the wall time and not the actual wall time. I'd really like a comment here to that effect like elapsed time is backoff-1 due to exponentiation so that the next person reading this code doesn't have to come to that conclusion on their own.

@bdrung
Copy link
Collaborator Author

bdrung commented Apr 17, 2024

The failing retries:

apport/packaging_impl/apt_dpkg.py:1479: SystemExit
----------------------------- Captured stderr call -----------------------------
WARNING: Package download error, retrying in 1 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 2 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 4 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 8 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 16 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 32 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 64 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 128 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 256 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 512 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 1024 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

WARNING: Package download error, retrying in 2048 second(s): Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

ERROR: Package download error, try again later: Failed to fetch http://ddebs.ubuntu.com/pool/main/c/coreutils/coreutils-dbgsym_8.32-4.1ubuntu1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/c/curl/libcurl4-dbgsym_7.81.0-1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]

So something clearly does not work correctly when retrying. It should succeed after some time.

Running the system tests on different releases in parallel can cause
some tests of `test_packaging_apt_dpkg` fail:

```
__________________ test_install_packages_dependencies[deb822] __________________
[...]
apport/packaging_impl/apt_dpkg.py:1326: SystemExit
----------------------------- Captured stderr call -----------------------------
ERROR: Package download error, try again later: Failed to fetch http://ddebs.ubuntu.com/pool/main/p/pcre2/libpcre2-8-0-dbgsym_10.39-3build1_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
Failed to fetch http://ddebs.ubuntu.com/pool/main/libs/libselinux/libselinux1-dbgsym_3.3-1build2_amd64.ddeb 429  Too Many Requests [IP: 185.125.190.18 80]
```

Retry package download if HTTP 429 'Too Many Requests' errors can be
found in the `apt.cache.FetchFailedException` error. The download is
retries with an exponential backoff and giving up after around one hour.

Signed-off-by: Benjamin Drung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants